How Ansible Works?
As already discussed, Ansible is a configuration management tool, based on push-based architecture to automate the configuration of your hosts to achieve the desired state.
Following are the components of Ansible architecture
- Inventory - Defines the list of target hosts
- Playbook (YAML file) - Defines a list of tasks
- Module - A python code invoked from tasks and executed on hosts
- Control Machine - Takes playbook and executes each task on a particular group of hosts
Playbook
A Playbook is a file that defines the desired state of your system.
It contains plays, which has a list of tasks to run in sequence against a list of hosts.
- A play is a set of tasks, grouped together to achieve an objective
- A task is an instruction you give to Ansible.
- They are written in YAML format, a data serialization language, that we discussed in previous cards.
Inventory

So Ansible captured the desired state through Playbook, but how would ansible know which machines it should configure through Inventory?
The Inventory file in Ansible contains the list of all hosts (target systems/servers) that need to be configured. You can also group hosts under different names as shown:
[group A]
Host 1
[group B]
Host 2
Host N
More on Inventory

- Default location of Inventory File: /etc/ansible/hosts
- You can define an Inventory file statically (.ini file) or dynamically (.json file) to Ansible.
Modules Perform the Action

Modules are a piece of code that gets executed when you run a playbook. You use them to describe the state you want the host to be in.
Each task in play is made of modules and arguments.
No comments:
Post a Comment