Ansible : A must knowing tool

Ansible : A must knowing tool

Ansible is an open source, command-line IT automation software application written in Python. It can configure systems, deploy software, and orchestrate advanced workflows to support application deployment, system updates, and more.

In Ansible, Ansible scripts are called playbooks. Playbook is a file written in YAML (Yet Another Markup Language) that defines a series of tasks to be executed on a group of hosts. Playbooks are used to automate complex tasks and workflows, making them an essential part of Ansible's configuration management and orchestration capabilities.

The amazing part with Ansible is :-

  • No agent is needed on the machine. (because it uses SSH,API,winRM).

  • No databases is required..

  • No complex setup is needed.

  • No residual software is left.

In Ansible server :-

Install Ansible through documentation https://docs.ansible.com/ansible/latest/installation_guide/installation_distros.html

Ansible has a default inventory file as :- /etc/ansible/hosts ,But it is recommended to create inventory in your repository so that you can fetch it anywhere and run your playbooks.

Example of a Inventory :-

And if you want to ping to the server's using a playbook, the playbook will look like :-

the command will be like :-

ansible-playbook -i inventory <playbook_name>

When connecting with server take care of :-

When control server connects with webservers it asks for Fingerprint and to avoid that :

  • Go to the config file

  • Remove ":" and change "True" to False from

  • ":host_key_checking=True"

Grouping in Ansible :

In Ansible, you can group hosts to organize them more effectively and apply tasks to specific groups of servers. Here's an example of how to create groups in your inventory file and use them in a playbook.

ad hoc commands in Ansible :

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.

It is great for tasks you repeat rarely.

$ ansible [pattern] -m [module] -a "[module options]"

Did you find this article valuable?

Support Saurabh's blog by becoming a sponsor. Any amount is appreciated!