Name: monitor-infrastructure
Owner: TABLEFLIP
Description: Infrastructure for the TABLEFLIP monitor
Created: 2016-11-24 11:35:11.0
Updated: 2017-02-15 09:53:06.0
Pushed: 2016-11-24 12:54:21.0
Homepage: null
Size: 25
Language: Nginx
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Ansible scripts for deploying the service
Vagrantfile # Test the scripts locally with `vagrant up`
group_vars # Common variables and deploy secrets
dev # Inventory of hosts used in local dev
next # Inventory of staging hosts
production # Inventory of LIVE hosts
roles # Define the tasks that set up a given role.
bootstrap.yml # Playbook for getting new vms up to spec
deploy.yml # Playbook for updating our app
Ansible works by assigning roles to hosts.
frontend
, db
, etc.Roles contain the tasks and and files to install and configure the services needed.
e.g: frontend
clones our app code, installs npm deps, and configures nginx as a proxy.
Key to making it work is ensuring tasks are idempotent. We can run all the tasks at any time. Either the task changes the system as required, or has no effect if that change is already in place.
An inventory defines named groups of servers. We use playbooks to assign roles those groups. We have a playbook that bootstraps a brand new vm to be used by ansible, which we assume will be run once on against each machine.
ble-playbook -i production bootstrap.yml --extra-vars "ansible_user=root"
where
-i production
limits the hosts affected to just those listed in production/inventory
bootstrap.yml
is the playbook to run.--extra-vars "ansible_user=root"
tells ansible to connect as root
for this run. It's only needed while we don't have an ansible user.bootstrap.yml
just steps up the ansible user and not much else.
sts: app
les:
- bootstrap
By assigning app
hosts the role bootstrap
, it's telling ansible to run the tasks defined in roles/boostrap/tasks/main.yml
me: Ensure base OS is up-to-date
come: yes
t: upgrade=dist update_cache=yes
me: Ensure ansible user exists
come: yes
er: name=ansible comment="Ansible" groups="ansible,sudo"
Once we have an ansible
user, we can forget about about bootstrap.yml
, and get on with setting up our roles, as defined in playbook.yml
At the start of a project, it's normal to have all the roles on the same host; a single vm dealing with the frontend, api and db, as it's then much easier to roll out additional VMs for staging and test.
When we need to scale the infrastructure we can add additional hosts to an inventory, to scale a roll horizontally across many identically configured servers, and we can split roles our to separate hosts, to create optimised VMs with a single purpose; e.g. a separate db
server.
brew install vagrant
)To bootstrap a local test server with vagrant
10.100.120.100 dev.monitor.tableflip.io
to your local /etc/hosts
wnload and provision a vm
ant up
date vm with our roles
ble-playbook -i dev deploy.yml
You now have a test vm, running locally
To bootstrap a new production vm
/root/.ssh/authorized_keys
on the remoteotstrap ansible user
ble-playbook -i production bootstrap.yml --extra-vars "ansible_user=root"
tall app and dependencies
ble-playbook -i production deploy.yml
See: http://docs.ansible.com/ansible/playbooks_vault.html
Creating Encrypting Files
Encrypt a list of files. You'll be prompted for a passphrase which'll be the key for decrypting them.
ble-vault encrypt [files]
For example, to encrypt our deploy keys and secrets, we do:
ble-vault encrypt group_vars/all/secrets.yml group_vars/dev/dev_secrets.yml group_vars/next/next_secrets.yml group_vars/production/production_secrets.yml
Editing Encrypted Files
ble-vault edit group_vars/production/production_secrets.yml
Will prompt you for the passphrase and open the file in your default $EDITOR as configured in your shell.