By default, Ansible looks at the /etc/ansible/hosts file for hosts specified in your playbook. As mentioned previously, I find it more expressive to specify the host file via the -i option. This is what we have been doing up to this point. To expand on our previous example, we can write our inventory host file as follows:
[ubuntu]192.168.199.170[nexus]192.168.199.148192.168.199.149[nexus:vars]username=ciscopassword=cisco[nexus_by_name]switch1 ansible_host=192.168.199.148switch2 ansible_host=192.168.199.149
As you may have guessed, the square bracket headings specify group names, so later on in the playbook we can point to this group. For example, in cisco_1.yml and cisco_2.yml, I can act on all of the hosts specified under the ...