Installing Ansible on Ubuntu
Prerequisites
Before installing Ansible, make sure you have the following prerequisites:
- Ubuntu 22.04 LTS system
- Python 3 installed
- sudo or root privileges
Install Ansible
- Update the package index:
sudo apt update
- Install the required packages:
sudo apt install software-properties-common
- Add the Ansible PPA (Personal Package Archive) to your system's sources list:
sudo add-apt-repository --yes --update ppa:ansible/ansible
- Install Ansible:
sudo apt install ansible
- Verify the installation:
ansible --version
You should see the Ansible version information displayed.
- Create an Ansible inventory file:
sudo nano /etc/ansible/hosts
Add the target hosts to the inventory file, for example:
[webservers]
192.168.1.100
192.168.1.101
[databases]
192.168.1.200
192.168.1.201
- Create an Ansible configuration file:
sudo nano /etc/ansible/ansible.cfg
Add the desired configuration options, for example:
[defaults]
inventory = /etc/ansible/hosts
remote_user = ubuntu
- Test the Ansible connection:
ansible all -m ping
This command will ping all the hosts in the inventory file and verify the connection.
Now, you have successfully installed Ansible on your Ubuntu 22.04 system and configured it to manage your target hosts.