This blog post introduces the fundamental concepts needed to get started with Ansible.

In the first article of the Terraform subseries, we briefly touched on how Terraform, an IaC tool for infrastructure provisioning, can run bash scripts on the servers and apply infrastructure configurations, but there are other IaC tools suitable for infrastructure configurations. Ansible is one such popular IaC tool, useful for configuring Linux servers, which is often used in combination with Terraform and other IaC tools. Hence, in this short subseries, we will discuss the basic concepts and techniques needed to get started with Ansible.
Why Ansible?
After setting up Linux servers for reverse proxy, web servers, database servers, and so on with Terraform or manually via GUI or CLI by cloud providers, we almost always need to run scripts to install software like nginx, web frameworks, database management systems, copy files and scripts for those software applications, and run them to start the services. If we would like to perform these tasks manually, we need to connect to every Linux server via SSH and run scripts that correspond to the roles of the servers and Linux distros, which is costly, error-prone, and hard to share and replicate. We also need to undergo this whole tedious process and renew the entire configurations for every change we make, which could be extremely redundant.
Ansible is an open-source IaC tool for system configurations for Linux servers, developed by Red Hat, that can address all of those problems. As an IaC tool, the code can be easily version controlled, shared, modified, and integrated with other tools. Ansible is also primarily declarative, allowing users to configure servers by only declaring the desired states in human-readable YAML files. With Ansible, we can easily handle different Linux distros and apply configurations to all servers at once and idempotently, meaning only necessary changes are applied. After changes are applied, we can be sure that the code represents the deployed states as well.
Ansible Workflow
Ansible assumes a setup consisting of a control node, which has Ansible installed and other configuration files, and managed nodes that the control node configures. The control node can be our local device or a remote server with a Unix-like operating system with Python installed to run Ansible (managed nodes also need Python installed for running Ansible scripts). The setup is agent-less and does not require managed nodes to install any agent for Ansible, which eliminates extra compute, memory, and storage requirements for the managed nodes and could be a strong reason for choosing Ansible over other similar tools.

To configure the servers with Ansible, we can just compose YAML files called playbooks and edit configuration files for Ansible and apply the changes to the managed nodes. This relatively simple workflow is also another benefit of choosing Ansible over the others. For version control and CI/CD, we can use Git/GitHub to store the playbooks and configuration files and incorporate the commands for applying the configurations in GitHub Actions. We can also combine other IaC tools like Terraform and Kubernetes by editing the playbooks and other files based on Terraform outputs and configuring servers to install Kubernetes packages and run the processes.
To get started with Ansible, you can download Ansible on the control node using pip install ansible
,
using a package manager, or by following the instructions in the official tutorial accessible
from here.
After installation, verify that it is successfully installed with ansible --version
.
In this short Ansible series, we are primarily configuring Linux servers for
web applications, but it is important to remember that its applications are not
limited to web applications. You may use virtual machines or remote servers
from cloud providers for following along and practicing using Ansible.
Conclusion
In this article, we covered the very basics of what Ansible is, why we might want to use Ansible, and how Ansible works. We also briefly discussed the installation requirements of Ansible. From the next article, we will begin discussing how to write Ansible playbooks and edit configuration files, details of some important and useful Ansible features, and their best practices. (Note: The contents and structure of this Ansible series are largely inspired by the tutorial course by Learn Linux TV (2020). I recommend checking it out from the link cited below if you are interested.)
Resources
- Ansible. n.d. Ansible Documentation. Ansible Community Documentation.
- Learn Linux TV. 2020. Getting started with Ansible. YouTube.