I like the idea of Michael DeeHan ‘infrastructure as data’, not ‘infrastructure as code’.
This is about this “a simple deployment, model-driven configuration management,
and command execution framework” tool he authored which is called Ansible.
Some of Ansible articles can be found also at:
http://www.coloandcloud.com/editorial/an-interview-with-ansible-author-michael-dehaan/
http://server.dzone.com/articles/ansible-cm-deployment-and-ad
http://highscalability.com/blog/2012/4/18/ansible-a-simple-model-driven-configuration-management-and-c.html
I will start with installing Ansible on MacOS. First, it’s best to setup virtualenv and virtualenvwrapper.
A good tutorial for this is Multiple Python Versions on OSX with Virtualenv and Homebrew
If configured correctly, start creating the Ansible environment and clone the code from github.
Cocoys-MacBook-Pro:~ cocoy$ mkvirtualenv ansi_env --no-site-packages Cocoys-MacBook-Pro:~ cocoy$ workon ansi_env
(ansi_env)Cocoys-MacBook-Pro:~ cocoy$ pip install yolk paramiko jinja2 PyYAML (ansi_env)Cocoys-MacBook-Pro:~$ yolk -l Jinja2 - 2.6 - active PyYAML - 3.10 - active Python - 2.6.6 - active development (/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload) paramiko - 1.7.7.1 - active pip - 0.6.3 - active pycrypto - 2.5 - active setuptools - 0.6c11 - active wsgiref - 0.1.2 - active development (/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6) yolk - 0.4.3 - active
Now clone the github for Ansible:
(ansi_env)Cocoys-MacBook-Pro:~ $ git clone https://github.com/ansible/ansible.git (ansi_env)Cocoys-MacBook-Pro:~$ cd ansible (ansi_env)Cocoys-MacBook-Pro:~$ git checkout devel (ansi_env)Cocoys-MacBook-Pro:~$ source ./env-setup (ansi_env)Cocoys-MacBook-Pro:~$ echo "server.domain.com" > myhost (ansi_env)Cocoys-MacBook-Pro:~$ export ANSIBLE_HOSTS=$(pwd)/myhost (ansi_env)Cocoys-MacBook-Pro:~$ ssh-add /path/to/server-ssh-keypair
Fire Ansible ping command:
(ansi_env)Cocoys-MacBook-Pro:~$ ansible all -m ping -u server_user server.domain.com | success >> { "ping": "pong" }
Now start adding more hostname to Ansible host file. 🙂
Oh, and btw, I’ve added some tiny patch here.
It support reading of .ssh/config file to get values for hostname,port, and ssh-keypairs.
Updated: Apr-30-2012, ssh config will not overrides Ansible’s user and hostname.
Updated: May-12-2012, ssh_config files is *NOT* read, considering playbook can possibly use different user for each play.
My Ansible hostfile:
[web-servers] hpcloud-a [cassandra-servers] ec2-xx-xx-xx.187.compute-1.amazonaws.com ec2-xx-xx-xx-52.compute-1.amazonaws.com
My SSH ~/.ssh/config
Host hpcloud-a HostName 15.185.123.xx User ubuntu IdentityFile /Users/cocoy/hpcloud.pem Host *.compute-1.amazonaws.com User ubuntu IdentityFile /Users/cocoy/ec2-keypair
(Note: On Amazon EC2, my two test instances the same keypair. On production, EC2 instances may have different keypair for each server (ex. db , web).
Now I can try running nodetool with Cassandra cluster:
(ansi_env) ~$ ansible cassandra-servers -m shell -a "nodetool -h localhost ring"
I notice that this can be close to Fabric on ad-hoc commands, but there are more features.
Next post?? Watch-out for templates and playbooks.
Update 07-03-2012: Now using source ./hacking/env-setup instead of source ./hacking-env as noted pointed by Scott.
Installing with pip/virtualenv would be good for the docs page. I’ll make a note to add it.
Pingback: Ansible Nginx Playbook
It looks like the env file in Ansible has moved. Rather than “source ./hacking-env”, you should now do “source ./hacking/env-setup”
Thanks Scott. I will note them.
Pingback: Using Ansible on EC2