Install Ansible on AlmaLinux 9/10
This guide provides a step-by-step installation of Ansible Automation Tool on AlmaLinux 9 and AlmaLinux 10 systems.
1. Prerequisites
- AlmaLinux 9 or AlmaLinux 10 server
- Sudo or root privileges
- Internet connectivity
- SSH enabled
- Minimum 2 GB RAM
- SELinux enabled
2. Set Hostname
sudo hostnamectl set-hostname ansible.example.com
3. Update System Packages
sudo dnf update -y
sudo reboot
4. Enable EPEL Repository
sudo dnf install -y epel-release
5. Install Required Packages
sudo dnf install -y \
wget \
curl \
git \
vim \
python3 \
python3-pip
6. Install Ansible
sudo dnf install -y ansible
7. Verify Ansible Installation
ansible --version
8. Generate SSH Key
ssh-keygen -t rsa -b 4096
9. Copy SSH Key to Remote Host
ssh-copy-id user@remote-server
10. Create Ansible Inventory File
sudo mkdir -p /etc/ansible
sudo vi /etc/ansible/hosts
11. Example Inventory Configuration
[webservers]
192.168.1.101
192.168.1.102
[dbservers]
192.168.1.201
[all:vars]
ansible_user=root
12. Test Ansible Connectivity
ansible all -m ping
13. Create Sample Playbook
vi install_httpd.yml
14. Example Ansible Playbook
---
- name: Install Apache Web Server
hosts: webservers
become: yes
tasks:
- name: Install Apache
dnf:
name: httpd
state: present
- name: Start Apache Service
service:
name: httpd
state: started
enabled: yes
15. Run Playbook
ansible-playbook install_httpd.yml
16. List Managed Hosts
ansible all --list-hosts
17. Configure Firewall (Optional)
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload
18. Install Additional Ansible Tools
sudo dnf install -y \
ansible-core \
python3-jmespath \
sshpass
19. Install Ansible Collections
ansible-galaxy collection install community.general
20. Optional Post Installation Tasks
- Configure Ansible Roles
- Configure Vault Encryption
- Setup AWX Dashboard
- Configure CI/CD Pipelines
- Create Reusable Playbooks