Hello! Welcome to the next lesson in our "Shell Scripting and Automation" module.
In our last lesson, we learned how to use Git to track changes in text files, like the shell scripts we've been writing. This is a powerful skill for managing your work. Now, let's ask a bigger question: What if we could use simple text files, managed with Git, to define and control the configuration of our entire servers? This is the core idea behind a practice called Configuration Management.
Today's lesson addresses the learning outcome: Explain the purpose of configuration management (e.g., Ansible). We will explore why this practice is essential for any modern Linux administrator and use Ansible, a leading automation tool, as our main example. This lesson provides the conceptual foundation you'll need before we dive into writing our first Ansible automation script in the next lesson.
1. The Problem: The Limits of Manual Administration
Imagine you're tasked with setting up a new web server. You SSH into the machine and run a series of commands to install Apache, configure a firewall, create user accounts, and tweak settings. This works for one server. But what happens when you need to set up ten? Or a hundred? And what happens when you need to apply a security patch to all of them consistently?
This is the problem that configuration management was created to solve.
What is configuration management and why you need Ansible, Chef, Puppet and others
To understand the challenge of managing servers at scale, let's watch a short video from mkdev that illustrates the progression from manual commands to simple scripts, and why both approaches fall short as complexity grows.
Watch from the beginning until 02:05. Pay attention to how a task that is simple for one server becomes unmanageable across many servers and environments (e.g., production, staging, testing).
As the video shows, relying on manual changes or even simple shell scripts leads to several problems:
- Scalability: It's impossible to manually manage hundreds of servers.
- Consistency: It's easy to make mistakes or forget steps, leading to servers that are configured differently. These unique, hard-to-replicate servers are often called "snowflake servers."
- Reproducibility: If a server fails, rebuilding it exactly as it was can be difficult and time-consuming.
2. The Solution: What is Configuration Management?
Configuration Management (CM) is the process of using automation tools to establish and maintain the consistency of a system's state. Instead of running commands manually, you define the desired state of your system in code.
An Introduction to Configuration Management
This article from DigitalOcean, "An Introduction to Configuration Management," provides an excellent summary of what CM is and its key benefits.
Please read the "Introduction" and the "Benefits of Configuration Management for Servers" sections. Focus on understanding the advantages it offers, especially how it prevents "snowflake servers" and enables version control for your infrastructure.
Core Principles of Configuration Management
CM tools like Ansible, Puppet, and Chef are built on a few core principles that differentiate them from simple scripting.
-
Declarative, not Imperative:
- An imperative approach (like a shell script) tells the system how to do something. For example:
apt-get install apache2. - A declarative approach tells the system what the end state should be. For example:
package: name=apache2 state=present.
The CM tool figures out the "how" for you, abstracting away the underlying commands for different Linux distributions (e.g.,aptvs.yum).
- An imperative approach (like a shell script) tells the system how to do something. For example:
-
Idempotency:
This is a crucial concept. An operation is idempotent if running it multiple times has the same effect as running it once.- A shell script that runs
useradd myuserwill fail if you run it a second time because the user already exists. - A CM tool with a declaration like
user: name=myuser state=presentwill check if "myuser" exists. If not, it creates the user. If the user already exists, it does nothing. The end state is the same, and no errors are thrown.
- A shell script that runs
This idempotent, declarative nature means you can run your configuration scripts against your servers repeatedly, and the tool will ensure they converge to the desired state, only making changes when necessary.
Test your understanding!
You need to ensure the htop utility is installed on 50 servers. Some may already have it, some may not.
You have two options:
A. A shell script with the command sudo apt install -y htop.
B. An Ansible task that says package: name=htop state=present.
If you run your chosen method on all 50 servers, what is the key difference in behavior between option A and option B?
Show answer
The key difference lies in idempotency.
- Option A (Shell Script): On every server, the
aptcommand will run. On servers that already havehtopinstalled,aptwill report that the latest version is already installed and do nothing. While the outcome is okay, the command unconditionally executes its logic every time. - Option B (Ansible Task): Ansible will first check the state of the
htoppackage on each server. It will only run the underlyingapt installcommand on servers wherehtopis not present. On servers wherehtopis already installed, Ansible will report the state as "ok" and move on without taking any action. This is more efficient and provides clearer reporting on what, if anything, was changed.
3. Ansible: The Agentless CM Tool
While there are many CM tools, Ansible has become extremely popular in the Linux world, and it's the one you are most likely to encounter. It is developed by Red Hat. Let's look at why.
The main difference between Ansible and older tools like Puppet or Chef is its architecture.

Key Features of Ansible
- Agentless: Ansible does not require any special software (an "agent") to be installed on the servers it manages. It communicates using standard SSH, which is already available on virtually all Linux systems. This dramatically simplifies setup. In contrast, tools like Puppet and Chef require an agent on every managed node that regularly checks in with a master server.
- Push Model: Ansible uses a "push" model. The control node pushes configurations out to the managed servers when you run a command. This contrasts with the "pull" model of Puppet/Chef, where agents on the managed servers periodically "pull" their configuration from a master server.
- Human-Readable YAML: Ansible's configuration files, called Playbooks, are written in YAML (YAML Ain't Markup Language). YAML is a simple, clean data-serialization language that is much easier to learn than the custom Ruby-based languages used by Puppet and Chef.
The Red Hat article "Learning Ansible basics" provides a concise summary of how Ansible works and its primary use cases.
Read the sections "How does Ansible work?", "Ansible Playbooks", and the "Configuration management" subsection under "How can you use Ansible Automation Platform?". This will reinforce the concepts of agentless automation, modules, and playbooks.
The combination of being agentless, using standard SSH, and employing a simple YAML syntax makes Ansible very approachable and powerful for Linux administrators. This is the core reason for its widespread adoption.
Conclusion
You now understand the fundamental purpose of configuration management and why tools like Ansible are indispensable in modern IT environments.
Key Takeaways:
- Purpose: Configuration Management automates server setup and maintenance to ensure consistency, scalability, and reproducibility.
- Core Principles: CM tools are declarative (you define the what, not the how) and idempotent (they can be run repeatedly with the same result).
- Ansible: A popular, powerful CM tool that stands out because it is agentless (uses SSH), employs a push model, and uses simple YAML for its playbooks.
- Infrastructure as Code: The practice of managing your infrastructure with configuration files (like Ansible playbooks) is called Infrastructure as Code. This allows you to use tools like Git—which you learned about in the last lesson—to version control your entire server environment!
Preview of the Next Lesson:
We've covered the "why" and "what" of configuration management and Ansible. In our next lesson, "Write a basic Ansible playbook to automate a simple system task," we'll get hands-on. You will apply these concepts by writing your first playbook to automate a common system administration task, turning theory into practice.