Created by Will Thames / @willthames
This presentation is available on Github Pages at:
http://willthames.github.io/devops-bris-ansible/
All code samples are included in the same repo, under examples
To save you having to remember that, I've published the info at http://willthames.github.io
I build the future!†
Vagrant.configure(2) do |config|
config.vm.define :shop do |shop|
shop.vm.box = "centos64-64"
shop.vm.network :private_network, ip: "192.168.0.2"
shop.vm.network :forwarded_port, guest: 22, host: 2202
end
config.vm.define :acct do |acct|
acct.vm.box = "centos64-64"
acct.vm.network :private_network, ip: "192.168.0.3"
acct.vm.network :forwarded_port, guest: 22, host: 2203
end
config.vm.provision :ansible do |ansible|
ansible.playbook = "provisioning/playbook.yml"
ansible.inventory_file = "provisioning/ansible_hosts"
ansible.sudo = true
end
end
---
- hosts: vagrant
tasks:
- name: add dummy host in /etc/hosts
action: lineinfile state=present regexp=repo.dev.example \
line='192.168.0.1 repo.dev.example'
- name: ensure /usr/local is writable by admin group
action: file state=directory group=admin mode=775 \
dest=/usr/local
Install from OS package (yum, apt-get etc) or
git clone http://github.com/ansible/ansible
pip install paramiko PyYAML jinja2
mkdir ~/.ansible
source ansible/hacking/env-setup -q
cat > ~/.ansible/config << EOT
[defaults]
hostfile = ~/.ansible/hosts
library = ~/src/ansible/library
EOT
ansible -m command -a date web
127.0.0.2 | success | rc=0 >>
Sun Aug 25 14:41:08 EST 2013
We'll use this environment for discussion purposes
DEMO!!!
Most configuration management frameworks have a way to have playbooks that include other playbooks.
Ansible recently introduced Role Dependencies, so that playbooks can include roles which can include other roles
This means that e.g. installing java or logstash can be separated out to roles
Configuration is typically multi-dimensional:
Also, there are typically groupings of targets - e.g. dev environments and prod-like environments
Here there are likely elements common to the dev environment such as mail gateways, log shipping destinations, log level.
There are also likely elements common to application type, such as files to log ship, JVM versions etc.
There are two key elements to repeatability:
This means that playbooks that install the latest version of an artifact, or checkout HEAD from version control are not repeatable.
Checks should be made when adding things - e.g. lines to a config file to ensure that it doesn't happen again on a second run
It's probably obvious that you should commit your playbooks to source control.
But you also need to manage versions. So that you can run playbook v1.2 against dev, v1.1 against test and v1.0 against prod as improvements flow through the pipeline.
There are many ways to achieve this, but cheap branching (typically DVCS) is an easy way - whether that's a dev branch or just pointing dev at the 1.2 branch.
What you don't want is your production database passwords, or Amazon private keys, or any other sensitive data written in plain text in source control.
Typically a solution is for the target nodes to have decryption keys and then the configuration management software decrypting it as it writes the config file
ansible-vault
is still a work in progress.
Unlike chef-cucumber and rspec-puppet, there are no common frameworks yet available. Using vagrant to test your changes in a throwaway VM will work in some cases.
Again, puppet has puppet-lint, chef has food-critic.
I've created an extensible lint for ansible at
http://github.com/willthames/ansible-lint
$ bin/ansible-lint examples/example.yml
[ANSIBLE0001] Old style (${var}) brackets
examples/example.yml:10
action: command echo ${oldskool}
[ANSIBLE0004] Checkouts must contain explicit version
examples/example.yml:22
action: git a=b c=d
...