Ansible works against multiple servers in your infrastructure at the same time.

  1. Inventory can be a folder - Create a folder, add as many inventory files inside this folder and instruct Ansible to use this folder as the inventory (with -i folder_name or in your ansible.cfg file). All inventory files inside the folder will be merged into one (including scripts like ec2.py)
  2. Inventory can be a file - Defaults Ansible inventory to being saved in the location /etc/ansible/hosts. You can change the Defaults Ansible inventory location in /etc/ansible/ansible.cfg as well.

Different inventory file using the -i <path> option on the command line.
$ ansible-playbook -i inventory playbook.yaml --key-file=remote.pem -u ec2-user

Multiple inventory files can be provided using folder for AWS
$ wget https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/ec2.py
$ ansible -i ec2.py playbook.yaml --key-file=remote.pem -u ec2-user

Multiple inventory files can be provided using folder for OpenStake
$ wget https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/openstack_inventory.py
$ chmod +x openstack_inventory.py
$ ansible -i openstack_inventory.py playbook.yaml --key-file=remote.pem -u ec2-user

 

Inventory Program 1

Content of file "inventory"

            
              192.168.33.20
              192.168.33.30
              hostname1
              hostname2