Skip to content

Ansible ​

configures both servers remotely, over . Everything installed on the machines is written in infra/ansible/: a server can be rebuilt from scratch with one command.

Files ​

FileRole
inventory.iniThe machines, in two groups: [dev] and [prod]
group_vars/all/main.ymlPlain variables: SSH user, /opt/trinity folder
group_vars/all/vault.ymlSecret variables, encrypted: runner tokens
playbook.ymlWhich roles to apply, in what order
roles/*/tasks/main.ymlEach role's tasks
yml
---
- name: Setup Trinity servers
  hosts: all
  become: true
  roles:
    - role: docker
      tags: docker
    - role: ufw
      tags: ufw
    - role: traefik
      tags: traefik
    - role: gitlab-runner
      tags: gitlab-runner

The four roles ​

What it does
dockerAdds Docker's official repository, installs Docker Engine and the Compose plugin, enables Swarm mode
ufwInstalls the firewall, allows 22, 80 and 443, blocks everything else
traefikCreates the trinity network, copies the config and the routes for the machine's group (dynamic/dev/ or dynamic/prod/), creates acme.json, starts Traefik
gitlab-runnerInstalls and registers the runners. See Runners

Each role has a tag with the same name, to run just one.

Running the playbook ​

sh
cd infra/ansible
ansible-playbook playbook.yml --ask-vault-pass                       # everything
ansible-playbook playbook.yml --tags traefik --ask-vault-pass        # a single role
ansible-playbook playbook.yml --limit prod --ask-vault-pass          # a single machine
ansible-playbook playbook.yml --check --diff --ask-vault-pass        # dry run, changes nothing

The playbook is : run again on an already configured machine, it only changes what differs.

Why Ansible rather than commands by hand?

A command typed by hand leaves no trace. With Ansible, the configuration is versioned, reviewed in merge requests, and reproducible: if a VM is lost, a new one is ready in minutes.

The Vault ​

group_vars/all/vault.yml is encrypted with . It can be committed: without its password, it is unreadable.

sh
ansible-vault view group_vars/all/vault.yml   # read
ansible-vault edit group_vars/all/vault.yml   # edit

The Vault password

It never goes into the repository. The .gitignore excludes .vault_pass* if you store it in a local file. It is passed from person to person, outside Git.

What the playbook does not do ​

  • It does not deploy the applications: that is the pipeline's job.
  • It does not create the VMs: they were created by hand in the Google Cloud console.
  • It does not manage the domains' DNS.