Install Ansible on RHEL 9/10

This guide provides a step-by-step installation of Ansible Automation Platform / Ansible Core on Red Hat Enterprise Linux (RHEL) 9 and RHEL 10.

1. Prerequisites


- RHEL 9 or RHEL 10 server
- Sudo or root privileges
- Valid Red Hat subscription
- Internet connectivity
- Minimum 2 GB RAM
- SSH enabled

2. Set Hostname


sudo hostnamectl set-hostname ansible.example.com

3. Register System with Red Hat


sudo subscription-manager register

sudo subscription-manager attach --auto

4. Enable Required Repositories


sudo subscription-manager repos \
--enable=rhel-9-for-x86_64-baseos-rpms \
--enable=rhel-9-for-x86_64-appstream-rpms

5. Update System Packages


sudo dnf update -y

sudo reboot

6. Install EPEL Repository


sudo dnf install -y \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm

7. Install Ansible


sudo dnf install -y ansible

8. Verify Ansible Installation


ansible --version

9. Configure SSH Access


ssh-keygen -t rsa -b 4096

ssh-copy-id user@remote-server

10. Create 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 Connectivity


ansible all -m ping

13. Create Simple Playbook


vi test-playbook.yml

14. Example Playbook


---
- name: Install Apache Web Server
  hosts: webservers
  become: yes

  tasks:
    - name: Install httpd
      dnf:
        name: httpd
        state: present

    - name: Start and enable httpd
      service:
        name: httpd
        state: started
        enabled: yes

15. Run Playbook


ansible-playbook test-playbook.yml

16. Check Managed Hosts


ansible all --list-hosts

17. Configure Firewall (Optional)


sudo firewall-cmd --permanent --add-service=ssh

sudo firewall-cmd --reload

18. Optional Ansible Tools


sudo dnf install -y \
ansible-core \
python3-pip \
git \
vim

19. Install Ansible Collections


ansible-galaxy collection install community.general

20. Optional Post Installation Tasks


- Configure Ansible Roles
- Configure Vault Encryption
- Setup AWX / Automation Controller
- Configure CI/CD Integration
- Create Custom Playbooks