When creating automation that is aimed at targeting one or multiple devices, we need a way to instruct Ansible which hosts to target and which playbooks should target which hosts. In order for Ansible to maintain an orderly congregation of hostnames, IP addresses, and domain names, the creators of Ansible have provided an Ansible inventory hosts file and the ability to group and target groups of hosts via Ansible playbooks. Ansible host are generally defined within the Ansible inventory hosts
file, which is traditionally located at the following file location on the Ansible control server:
/etc/ansible/hosts
As we mentioned in the previous chapter, the Ansible hosts
file allows the Ansible developer to maintain a list or set of groups of devices that Ansible can target via playbooks. The way we instruct Ansible to target specific groups of hosts is through the hosts
line entry within a given Ansible playbook. Let's consider the following hosts groups and Ansible playbook...