# Ansible Configs and Settings
### Ansible Config File
Ansible looks for the ***ansible.cfg*** file at the following locations (and in that order of precedence):
**Environment Variables (if set)**
````y=
ANSIBLE_CONFIG
````
**Current Directory**
````y=2
ansible.cfg
````
**Home directory (current user)**
````yaml=3
~/.ansible.cfg
````
**or**
````yaml=4
/etc/ansible/ansible.cfg
````
### Working with Ansible Inventory
**Inventory File Location**
````y=
/etc/ansible/hosts
````
**On Ansible Controller**
:mag: Please make the changes and update your local hosts file inside /etc/ansible directory. Sample entries mentioned below
````go=1
sudo vi /etc/ansible/hosts
[nodes]
w1 ansible_host=178.62.122.74
w2 ansible_host=159.65.51.250
[centos]
159.65.51.250
[ubuntu]
178.62.122.74
[webservers]
178.62.122.74
159.65.51.250
[allnodes:children]
w1
w2
````
**Validate the groups you have just created**
````go=1
ansible --list-hosts all
ansible --list-hosts <groupname>
ansible --list-hosts webservers
hosts (3):
localhost
172.31.57.187
172.31.49.9
````
:mag: *Note: You might have to add the users (labsuser or ansible) to admin (ubuntu) or wheel (redhat) group in order to get sudo access. Please run the following command in order to do it:*
````go=1
Syntax:
usermod -aG <groupname> <username>
Command Example:
usermod -aG admin ansible
````
### Working with Multiple inventory files
#### Providing a different inventory file using -i flag
````go=1
Syntax:
ansible -m ping -i <filename> <group-name>
Sample Command:
ansible -m ping -i newhosts new-nodes
````
#### Update a new inventory location in ansible.cfg
````go=1
/etc/ansible/ansible.cfg
[defaults]
inventory = /etc/ansible/hosts
````
:mag: *Note: Checkout following github page for more Ansible configuration defaults and customizations --> https://github.com/ansible/ansible/blob/stable-2.9/examples/ansible.cfg*
### configure DNS compliant names in host file
````go=1
sudo vi /etc/ansible/hosts
[nodes]
w1 ansible_host=178.62.122.74
w2 ansible_host=159.65.51.250
````