We do not need Ansible if we have no remote target to manage, correct? Everything starts from the fact that we need to manage some task on a remote host. The way we specify the potential remote target is with a host file. We can either have this file specifying the remote host either in /etc/ansible/hosts or use the -i option to specify the location of the file. Personally, I prefer to have this file in the same directory where my playbook is.
The inventory file is a simple, plain text INI-style file that states your target. By default, this can either be a DNS FQDN or an IP address:
$ cat hosts
192.168.199.170
We can now use the command-line option to test Ansible and the host file:
$ ansible -i hosts 192.168.199.170 -m ping
192.168.199.170 | SUCCESS => {
"changed": false,
"ping": "pong"
}
The previous line reads that we will use the host file as the inventory file, and execute the ping module on the host called 192.168.199.170. Ping (http://docs.ansible.com/ansible/ping_module.html) is a trivial test module that connects to the remote host, verifies a usable Python installation, and return the output pong upon success.
If you get a host key error, it is typically because the host key is not in the known_hosts file, and is typically under ~/.ssh/known_hosts. You can either ssh to the host and answer yes at adding the host, or you can disable this checking on /etc/ansible/ansible.cfg or ~/.ansible.cfg with the following code:
[defaults]
host_key_checking = False
Now that we have a valid inventory file, we can make our first playbook.