Setting-up Hosts file
- Default directory for hosts file is /etc/ansible
- Create a directory in /home/ec2-user using:
mkdir ansible cd ansible
- Lets create our own hosts file in /home/ec2-user/ansible using
vim hosts-dev
Content of hosts-dev
# hosts-dev [webservers] <IP_ADDRESS> <IP_ADDRESS> [loadbalancers] <IP_ADDRESS> [local] control ansible_connection=local
OR
# hosts-dev [webservers] app1 ansible_host=<IP_ADDRESS> app2 ansible_host=<IP_ADDRESS> [loadbalancers] lb1 ansible_host=<IP_ADDRESS> [local] control ansible_connection=local
- Now try to get inventory files using:
ansible -i hosts-dev --list-hosts all