18 - Configuration Management Tools Study Guide
18 - Configuration Management Tools Study Guide
com**
Configuration management is a key component of modern IT operations, enabling automated control over
software, hardware, and infrastructure. Tools like Ansible allow administrators to define configurations
declaratively and manage servers through automated scripts, reducing manual effort and ensuring consistency
across environments.
In this chapter, we will walk through setting up and using Ansible—a popular configuration management
tool—on AWS, where we will create multiple servers (EC2 instances) and use Ansible to manage and configure
them automatically. By the end of this chapter, you’ll understand how to:
To follow along, you need an active AWS account. Once you have access, the first step is to prepare your AWS
environment by creating several virtual servers using EC2 (Elastic Compute Cloud) and ensuring they can
communicate with Ansible.
AWS uses VPC (Virtual Private Cloud) to logically isolate network environments. Most AWS regions have a
default VPC configured, which includes basic networking components like subnets and security groups. In this
lesson, we use the default VPC to simplify networking setup.
Ansible requires installation on a machine from which it can control other nodes (servers). This control node
will issue commands to the other nodes based on playbooks.
bash
Copy code
sudo apt update
3. Install Ansible:
o To install Ansible, execute:
bash
Copy code
sudo apt install ansible -y
The inventory file in Ansible specifies which servers it will manage. The inventory is organized by groups,
such as web servers or database servers.
bash
Copy code
nano inventory
o In this file, define the groups and the IP addresses of the servers:
ini
Copy code
[web]
172.31.25.137 # Web1 Private IP
172.31.22.189 # Web2 Private IP
[control]
172.31.26.199 # Control VM Private IP
For Ansible to manage the servers, it needs SSH access to them. When you created the instances, AWS
provided a key pair for secure access.
bash
Copy code
scp -i ansible-key.pem ansible-key.pem ubuntu@<Control_VM_Public_IP>:~/
bash
Copy code
chmod 400 ansible-key.pem
bash
Copy code
ssh -i ansible-key.pem ubuntu@<Web1_Private_IP>
Ansible uses playbooks written in YAML to define the desired configuration on managed servers. A playbook
specifies a series of tasks for Ansible to execute.
bash
Copy code
nano setup-web-server.yml
2. Define the Playbook:
o Use the following YAML code to define the steps for installing Apache on the web servers:
yaml
Copy code
---
- hosts: web
become: yes
tasks:
- name: Install Apache
apt:
name: apache2
state: present
- name: Start Apache
service:
name: apache2
state: started
enabled: yes
Now that we have our playbook and inventory set up, it's time to run the playbook and configure our web
servers.
bash
Copy code
ansible-playbook -i inventory setup-web-server.yml --private-key ansible-
key.pem
Cleaning Up
To avoid unnecessary charges from AWS, ensure that you terminate the EC2 instances when finished.
1. Terminate Instances:
o Go to the EC2 Dashboard.
o Select the instances (Web1, Web2, Control VM) and click Terminate.
2. Verify Termination:
o Ensure that the status of the instances changes to terminated.
Conclusion
In this chapter, we learned how to set up configuration management using Ansible on AWS. We created EC2
instances, installed Ansible on a control node, wrote an inventory file and a playbook, and automated the
installation of Apache on multiple web servers. Ansible simplifies configuration management by automating
tasks across multiple servers, ensuring consistency and efficiency in managing IT environments.