Tasks are run against target servers. Some Ansible documentation refers to the target servers as "hosts".
After a clean install of Ansible, the default hosts file is /etc/ansible/hosts. The default hosts file is completely commented out. If you were to issue command ansible all -m ping, the following would be displayed.
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
Ansible uses inventory plugins to parse inventory. For example, ansible.cfg may have the following.
enable_plugins = host_list, yaml, ini
For example, the yaml inventory_plugin allows you to define target servers in a YAML default hosts file or your own inventory file. For example, let's say you have an default hosts file or your own inventory file named inventory.yml that contains target systems, perhaps something like this.
Here is how you can run the example.yml playbook using the target systems specified in inventory.yml.
ansible-playbook example.yml --inventory /path/to/inventory.yml
There are multiple ways to define your inventory:
- Append managed nodes to the default hosts file (/etc/ansible/hosts) on your Ansible control node
- Create an alternative hosts file, also known as a static inventory file on your Ansible control node
- Create a dynamic inventory file on your Ansible control node
- Update the "inventory" directive in ansible.cfg to point to the location of the default hosts file or your own inventory file
- Create a static inventory in Ansible Tower
- Create a smart inventory in Ansible Tower