Ansible = “Infrastructure as Data, Not infrastructure as Code”

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:

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        -      - 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 
(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 "" >   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 | 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:



My SSH ~/.ssh/config

Host hpcloud-a
  HostName 15.185.123.xx
  User ubuntu
  IdentityFile /Users/cocoy/hpcloud.pem 

Host *
  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.

5 thoughts on “Ansible = “Infrastructure as Data, Not infrastructure as Code”

  1. Pingback: Ansible Nginx Playbook

  2. Scott

    It looks like the env file in Ansible has moved. Rather than “source ./hacking-env”, you should now do “source ./hacking/env-setup”

  3. Pingback: Using Ansible on EC2

Leave a Reply

Your email address will not be published. Required fields are marked *