Curriculum
Course: Developer Operation (DevOps)
Login
Text lesson

Configuration Management

Introduction to Configuration Management Tools

 

Configuration management is the process of defining, establishing, and maintaining the consistency of a server’s performance, functional, and physical attributes. It automates the installation of software, the configuration of services, and the management of files.

  • IaC vs. Configuration Management: It’s important to understand the distinction. IaC (e.g., Terraform) creates and manages the underlying resources (the servers themselves), while configuration management (e.g., Ansible) configures what’s on those servers. Think of it as IaC building the house, and configuration management furnishing it.

  • Popular Tools: The most common tools are Ansible, Chef, and Puppet. They all serve a similar purpose but have different approaches. We’ll focus on Ansible due to its simplicity and agentless nature.

Ansible: The Key Concepts

 

Ansible is an open-source automation tool that automates software provisioning, configuration management, and application deployment. Its main advantage is that it is agentless. It doesn’t require any special software to be installed on the servers it manages; it simply connects via SSH.

Playbooks 

A playbook is the core of an Ansible workflow. It’s a YAML file that defines a set of tasks to be executed on a list of hosts. A playbook is the blueprint for a desired state.

  • YAML: Ansible playbooks are written in YAML (YAML Ain’t Markup Language), which is a human-readable data serialization language.

  • Plays & Tasks: A playbook consists of one or more plays. Each play defines a group of tasks to be executed on a specific group of hosts. A task is a single action to be performed, like installing a package or copying a file.

Here’s a simple playbook to install nginx and start the service:

YAML

---
- name: Install and start Nginx
  hosts: webservers
  tasks:
    - name: Install Nginx
      ansible.builtin.apt:
        name: nginx
        state: present

    - name: Start and enable Nginx service
      ansible.builtin.systemd:
        name: nginx
        state: started
        enabled: yes

 

Modules 

Modules are the individual, reusable scripts that perform the actual work in Ansible. Ansible ships with a vast library of modules for a wide range of tasks, such as managing packages, services, and files, or interacting with cloud providers. In the playbook above,  and ansible.builtin.systemd are modules.

Roles 

Roles are a way to organize your playbooks and other related files (like templates and variables) into a reusable and shareable structure. A role is a logical grouping of tasks that perform a specific function, such as configuring a web server or a database.

  • Structure: A role has a standard directory structure with folders for task, handlers, templates, and vars.

  • Reusability: Roles make it easy to reuse configurations across different projects. For example, you can have an nginx role that can be applied to any server that needs to be configured as a web server.

  • Separation of Concerns: Roles promote best practices by separating different concerns into their own logical units.