Setting-Up Ansible Configuration file
- In last lab, we got the inventory of host from Ansible by running
ansible -i hosts-dev –list-hosts all
- Above we needed to specify Ansible which host file to refer, we can declared reference in ansible.cfg then we wouldn’t need to specify hosts file again
- Default directory for ansible.cg is /etc/ansible
- Lets create our own ansible .cfgfile in /home/ec2-user/ansible using
vim ansible.cfg
Content of ansible.cfg
# ansible.cfg [defaults] inventory = ./hosts-dev
- Now try to following commands:
ansible --list-hosts all ansible --list-hosts webservers ansible --list-hosts loadbalancers ansible --list-hosts webservers:loadbalancers ansible --list-hosts webservers[0]