Ansible It is a RedHat It is a configuration management tool It is a Push based configuration tool. It is infrastructure as a Code ( IaC...
Ansible
- It is a RedHat
- It is a configuration management tool
- It is a Push based configuration tool.
- It is infrastructure as a Code (IaC) but we can manage network, containers, cloud, security, applications using Ansible
- It is agentless means we need to install Ansible only on the Master node and connect to the agent using the master's ssh public key( ssh-keygen)
- To Manage IaC using Ansible you can use Ansible Adhoc Commands or Ansible playbooks (script).
Ansible Architecture.
Master Server
The Server where Ansible is installed and using Ansible you are managing the configuration on host machines (Agent machine)
Host servers/machines
These are agent machines where you need to change the configuration using Ansible. For example, if you need to change the configuration on webservers and DB servers then webservers and DB servers are host servers.
Inventory or host file.
It is a file where all host machines' IP addresses or FQDN ( Full qualified domain name) are mentioned.
By default the path is /etc/ansible/hosts
Below are the formats by which we can configure hosts machines IP or FQDN in the hosts file
IP Addresses:- You can specify the IP addresses of your host machine.
Group:- You can add IP address which is relevant to a group. For example, if you have 2 IPs 192.168.10.10 and 192.168.10.11 are web servers then you can specify a group called webservers
[webservers]
192.168.10.10
192.188.10.11
Range:- You can also define a range of domain names in the host file. In below example, we are specifying domain names like db-99.mydomain to db-110.mydomain.com
db-[99-110].mydomain.com
Ansible Modules
- Modules are used to accomplish automation tasks in Ansible. These programs are written to be resource models of the desired state of the system. Ansible then executes these modules and removes them when finished. Without modules, you'd have to rely on ad-hoc commands and scripting to accomplish tasks.
- Modules are used with Adhoc commands as well as with playbooks.
- Modules are having attributes or properties which help to define the desired state of a given task.
- For example, if you want to install an apache server on a Ubuntu machine then the apt module has a property called name and state where name indicates package name (apache2) and state indicates installed, removed etc.
- To display all the modules ( ansible-doc -l)
- To search a particular module ( ansible-doc -s yum)
Example:
- yum module represents yum package manager
- apt module represents package manager for Debian-based OS.
Ansible configuration file (ansible.cfg)
It is the file that has settings related to the Ansible package.
for example
Change the inventory path
Change role path
Ansible Adhoc Commands:
An Ansible ad hoc command uses the /usr/bin/ansible command-line tool to automate a single task on one or more managed nodes. ad hoc commands are quick and easy, but they are not reusable. So why learn about ad hoc commands first? ad hoc commands demonstrate the simplicity and power of Ansible.
Ansible PlayBooks:
Ansible playbooks are the script files that are used for managing the infrastructure on host machines that are configured in the inventory file.For example if you want to install a package on Webservers then you can write a yaml script (playbook) to install package on webservers.
COMMENTS