Switch branches/tags
Nothing to show
Find file History
Failed to load latest commit information.
README.md Ansible 2.0 syntax on steps 0,1,2 Jan 29, 2016
hosts Ansible 2.0 syntax on steps 0,1,2 Jan 29, 2016


Ansible tutorial


Before continuing, you need an inventory file. The default place for such a file is /etc/ansible/hosts. However, you can configure ansible to look somewhere else, use an environment variable (ANSIBLE_HOSTS), or use the -i flag in ansible commands an provide the inventory path.

We've created an inventory file for you in the directory that looks like this:

host0.example.org ansible_host= ansible_user=root
host1.example.org ansible_host= ansible_user=root
host2.example.org ansible_host= ansible_user=root

ansible_host is a special variable that sets the IP ansible will use when trying to connect to this host. It's not necessary here if you use the vagrant-hostmaster gem. Also, you'll have to change the IPs if you have set up your own virtual machines with different addresses.

ansible_user is another special variable that tells ansible to connect as this user when using ssh. By default ansible would use your current username, or use another default provided in ~/.ansible.cfg (remote_user).


Now that ansible is installed, let's check everything works properly.

ansible -m ping all -i step-01/hosts

What ansible will try to do here is just executing the ping module (more on modules later) on each host.

The output should look like this:

host0.example.org | success >> {
    "changed": false, 
    "ping": "pong"

host1.example.org | success >> {
    "changed": false, 
    "ping": "pong"

host2.example.org | success >> {
    "changed": false, 
    "ping": "pong"

Good! All 3 hosts are alive and kicking, and ansible can talk to them.

Now head to next step in directory step-02.