This repository documents my journey in learning Ansible, an open-source automation tool. As a self-learner, I'm using this project to understand and apply Ansible concepts for infrastructure automation and configuration management.
The project currently includes:
- Ansible configuration file (
ansible.cfg
) - Ansible playbook for system updates and web server setup
- Inventory file
[default]
inventory = inventory
private_key_file = ~/.ssh/ansible
This configuration file sets up the following defaults:
- The inventory file is named
inventory
and is expected to be in the same directory as theansible.cfg
file. - The private SSH key for connecting to managed nodes is located at
~/.ssh/ansible
.
---
- hosts: all
become: true
tasks:
- name: install updates (Ubuntu)
apt:
upgrade: dist
update_cache: yes
when: ansible_distribution_version == "Ubuntu"
- hosts: web_servers
become: true
tasks:
- name: install apache and php for Ubuntu servers
apt:
name:
- apache2
- libapache2-mod-php
state: latest
when: ansible_distribution == "Ubuntu"
This playbook does the following:
- Updates all Ubuntu systems in the inventory.
- Installs Apache web server and PHP on hosts in the
web_servers
group, but only for Ubuntu distributions.
[web_servers]
192.168.51.247
192.168.51.248
[file_servers]
192.168.51.249
This inventory file defines two groups of servers:
web_servers
: Contains two servers (192.168.51.247 and 192.168.51.248)file_servers
: Contains one server (192.168.51.249)
- Understanding Ansible configuration basics
- Managing inventory in Ansible
- Secure connection to managed nodes using SSH keys
- Writing and structuring Ansible playbooks
- Using conditionals in Ansible tasks
- Managing system updates with Ansible
- Installing and configuring web servers
- Organizing hosts into groups for targeted automation
- Ensure you have Ansible installed on your control node.
- Place the
ansible.cfg
file in your project's root directory. - Create the
inventory
file in the same directory with the provided content. - Ensure you have the appropriate SSH key at
~/.ssh/ansible
. - Create a playbook file (e.g.,
site.yml
) with the provided playbook content. - Run the playbook using the command:
ansible-playbook site.yml
- Expand the playbook to include tasks for
file_servers
- Implement role-based access control for different server groups
- Explore Ansible modules for file management and other server configurations
- Learn about Ansible roles for better organization of tasks
- Implement error handling and logging in playbooks
- Explore Ansible Vault for managing sensitive data
- Understanding the structure of Ansible playbooks
- Learning to use conditionals to target specific distributions
- Figuring out how to manage different tasks for different host groups
- Organizing and managing inventory for different server roles
This is a learning project and may not reflect best practices for production environments. Always refer to official documentation and security best practices when working on real-world projects.