Ansible Continued
- While running the playbooks we can see more logs of whats happening when the playbook executes
- -v:

- -vv:

- -vvv:

- -vvvv: Connection debugging
- -v:
- Ansible configurations are store in the directory /etc/ansible in the file ansible.cfg

- The hosts file in /etc/ansible is the default inventory file.
- While running playbook’s if you dont provide any inventory then this default inventory is picked up
- The behavior of ansible like default inventory, module search path & many more are picked up from ansible configuration file at /etc/ansible/ansible.cfg
Adhoc Command
- From ansible we can run modules, This module is expressed as yaml and we use it tasks or handler section which leads to playbook.
- Ansible modules can be executed directly as command line which is referred as adhoc command
ansible -m <name of module> -a <arguments>
- We have used the ping module to check the connection
ansible -i inventory -m ping all

- Lets try to install git on the localhost using adhoc command. The manual command is
sudo apt update && sudo apt install git -y - Lets use the adhoc command documentation Refer Here
ansible -b -m 'apt' -a 'name=git update_cache=yes state=present' all

Inventory in Ansible
- Generally when we work with deployments we would have number of servers to deal and servers are grouped according to the applications they run for example webservers, db servers, ubuntu server etc..
- In the inventory file we can create groups
[webserver]
172.31.17.152
[dbserver]
172.31.29.133
[ubuntu]
172.31.17.152
localhost
[centos]
172.31.29.133
-
Then for exploring we have run some ansible ping adhoc commands

-
Ansible has two kinds of inventory
- Static Inventory
- Dynamic Inventory
-
Next Steps:
- Different formats for writing inventories
- Static vs Dynamic Inventory
- Ansible Variables
