Classes: Introduction to Ansible for a robust Configuration Management
Do you need a robust configuration management? If you have managed lots of server with lots of configuration manually, then you know how difficult it is. This is where Ansible can help you to have better server management and configuration standardization without too much hassle.
What is Ansible?
- Ansible is an open-source IT Configuration Management, Deployment & Orchestration tool.
- It aims to provide large productivity gains to a wide variety of automation challenges.
For example, you are going to config SMTP servers or collect logs from SMTP servers.
- This tool is very simple to use but powerful enough to automate complex application environments.
- Ansible is an automation tool that provides a way to define infrastructure as code.
- Infrastructure as code (IAC) simply means that managing infrastructure by writing code rather than using manual processes.
- you don’t even need to know the commands used to accomplish a specific task.
For example, when adding a new user on Linux OS. Normally, you need to run more than 2 commands to add the new user
- In ansible, you just need to specify what state you want the system to be in, and then Ansible will take care of it.
(In case of adding user, state can be “present” or “absent”)
- For example,
- Task for create new user
– name: Manage Users
tags: – usergroup
- Task for create new user
Ansible works by connecting via SSH to remote hosts that are listed on inventory file such as /etc/ansible/hosts. You can do a simple command by using Ansible adhoc command. For example, to get a date from a server you can do it like “ansible –m command SERVER date”.
You can also do a complete setup on a server like installing apps and configuring them on a server using Ansible Playbook. Playbook is a template which “Infrastructure as a Code” term refers as a Code.
Playbook will have modules, inventory, and tasks. Since Playbook is a template, then we can use it as a standard and centralized configuration for all the servers provisioning. Also, we can share the templates and modify it as needed.
Generally, Ansible uses these terminologies below:
- Controller Machine: Machine to install Ansible
- Inventory: detail info regarding servers to be managed
- Playbook: Automation is defined using tasks defined in YAML format
- Task: Procedure to be executed
- Module: Predefined command execute directly on remote hosts
- Play: Execution of a playbook
- Role: a Pre-defined way for organizing playbooks
- Handlers: Tasks with unique names. Another task will execute it if there is any notification.
(For an example of the configuration, please visit “Classes: Install and Configure Ansible” and “Classes: Post Installation”)
Advantages of Ansible for Configuration Management
- Ansible is an open-source tool.
- Ansible’s playbooks does not require special coding skills.
- It also allows you to model even highly complex IT workflows.
For example, you need add a repository based on the OS version.
- You do not need to install any agent on the target systems you want to automate.
- You do not need to set up a separate management structure like puppet.
- Since you don’t have to install any extra software, there is more room for application resources on your server.
- Ansible is simple, reliable, and consistent for configuration management.
- Secure and consistent
Because Ansible only uses SSH and Python on the managed nodes, it ensures safety and security.
Ansible playbook can be idempotent when written carefully. This prevents unexpected side-effects on the managed systems.
An operation is idempotent if the result of performing it once is exactly the same as the result of performing it repeatedly without any intervening actions (denoting an element of a set which is unchanged).
Lastly, if you want to know about how to install and configure ansible, you can find out by reading this article.