An Introduction to Configuration Management with Ansible
Written by Erika Heidi
Introduction
Configuration management is the process of handling changes to a system in a way that assures integrity over time, typically involving tools and processes that facilitate automation and observability. Even though this concept didn’t originate in the IT industry, the term is broadly used to refer to server configuration management.
In the context of servers, configuration management is also commonly referred to as IT Automation or Server Orchestration. Both terms highlight the practical aspects of configuration management and the ability to control multiple systems from a central server.
This guide will walk you through the benefits of using a configuration management tool to automate your server infrastructure setup, and how one such tool, Ansible, can help you with that.
Benefits of Using a Configuration Management Tool
There are a number of configuration management tools available on the market, with varying levels of complexity and diverse architectural styles. Although each of these tools have their own characteristics and work in slightly different ways, they all provide the same function: make sure a system’s state matches the state described by a set of provisioning scripts.
Many of the benefits of configuration management for servers come from the ability to define your infrastructure as code. This enables you to:
Use a version control system to keep track of any changes in your infrastructure Reuse provisioning scripts for multiple server environments, such as development, testing, and production Share provisioning scripts between coworkers to facilitate collaboration in a standardised development environment Streamline the process of replicating servers, which facilitates recovery from critical errors
Additionally, configuration management tools offer you a way to control one to hundreds of servers from a centralized location, which can dramatically improve efficiency and integrity of your server infrastructure.
Ansible Overview
Ansible is a modern configuration management tool that facilitates the task of setting up and maintaining remote servers, with a minimalist design intended to get users up and running quickly.
Users write Ansible provisioning scripts in YAML, a user-friendly data serialization standard that is not tied to any particular programming language. This enables users to create sophisticated provisioning scripts more intuitively compared to similar tools in the same category.
Ansible doesn’t require any special software to be installed on the nodes that will be managed with this tool. A control machine is set up with the
Ansible software, which then communicates with the nodes via standard SSH.
As a configuration management tool and automation framework, Ansible encapsulates all of the common features present in other tools of the same category, while still maintaining a strong focus on simplicity and performance:
Idempotent Behavior
Ansible keeps track of the state of resources in managed systems in order to avoid repeating tasks that were executed before. If a package was already installed, it won’t try to install it again. The objective is that after each provisioning execution the system reaches (or keeps) the desired state, even if you run it multiple times. This is what characterizes Ansible and other configuration management tools as having an idempotent behavior. When running a playbook, you’ll see the status of each task being executed and whether or not the task performed a change in the system.
Support to Variables, Conditionals, and Loops
When writing Ansible automation scripts, you can use variables, conditionals, and loops in order to make your automation more versatile and efficient.
System Facts
Ansible collects a series of detailed information about the managed nodes, such as network interfaces and operating system, and provides it as global variables called system facts. Facts can be used within playbooks to make your automation more versatile and adaptive, behaving differently depending on the system being provisioned.