This video tutorial guides you through installing Ansible on Ubuntu 24.04 LTS, along with configuration and a demo project showcasing its capabilities.
Ansible is an open-source automation tool that simplifies IT infrastructure management. Written in plain English playbooks, Ansible lets you deploy applications, configure systems, and orchestrate complex workflows with ease.
**Simple and Beginner-Friendly**: Playbooks use YAML, a human-readable language, making Ansible easy to learn.
**Agentless Design**: Forget additional agents; Ansible leverages SSH for secure communication with managed systems.
**Powerful and Flexible**: Ansible tackles a wide range of tasks, from basic configuration to intricate deployments.
Lab Setup
This demonstration utilizes three VMs:
*VM1* [Ubuntu 24.04, 192.168.1.7] : Ansible Control Node
*VM2* [Fedora 40, 192.168.1.8]: Managed Host 1
*VM3* [Ubuntu 24.04, 192.168.1.9]: Managed Host 2
Prerequisites
Configure a "sysops" user with sudo privileges (no password prompt) on all VMs using:
echo "sysops ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/sysops
###Installation Steps ####
1. *Add Ansible PPA:*
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository --yes --update ppa:ansible/ansible
2. *Install Ansible:*
sudo apt install -y ansible
3. *Verify Installation:*
ansible --version
4. *Configure Passwordless SSH:*
Generate SSH keys for the "sysops" user on the control node and share the public key with managed hosts using `ssh-keygen` and `ssh-copy-id`.
Project Setup
1. *Create Project Directory:*
mkdir ansible-demo
cd ansible-demo
2. *Initialize Ansible Configuration:*
ansible-config init --disabled | tee ansible.cfg
3. *Edit `ansible.cfg`:*
Use `vi` to edit `ansible.cfg`. Update the following sections:
[defaults]
inventory = /home/sysops/ansible-demo/inventory
remote_user = sysops
host_key_checking = False
[privilege_escalation]
become=True
become_method=sudo
become_user=root
become_ask_pass=False
4. *Create Inventory File:*
Use `vi` to create an inventory file with the following content:
[dev]
192.168.1.8
[release]
192.168.1.9
Testing the Setup
1. *Verify Configuration:*
ansible --version
2. *Test Connectivity:*
ansible all -m ping
3. Create a sample playbook
vi packages.yaml
---
name: Playbook to Install LAMP on Release env
hosts:
release
tasks:
name: Install PHP, MariaDB and Apache
package:
name:
php
mariadb-server
apache2
state: present
name: Playbook to Install Nginx on Dev env
hosts:
dev
tasks:
name: Install NGINX
package:
name:
nginx
state: present
4. Run the play book
ansible-playbook -i inventory packages.yaml --check
ansible-playbook -i inventory packages.yaml --check
5. Run Ansible ad-hoc command to verify the changes
ansible dev -m shell -a 'rpm -qa | grep "nginx"'
ansible release -m shell -a 'dpkg -l | grep -E "php|mariadb|apache2"'
#howto #ansible #ubuntu2404 #automation
If you have found this tutorial informative and useful, kindly do subscribe our channel and like the video.
Web Site : www.linuxtechi.com
YouTube Channel : / @linuxtechi9979
######################################
Thank you for Watching!!
######################################