Ansible Installation on Ubuntu
Learn how to install and configure Ansible for network automation. This guide covers basic concepts, installation steps, and essential components.
Ansible Installation on Ubuntu
This guide focuses on installing Ansible on an Ubuntu virtual machine, which will serve as your Ansible control node within the lab environment.
Installing Ansible on the Ubuntu Control Node
You can install Ansible on your Ubuntu VM using either apt
(package manager) or pip
(Python package installer). pip
is generally recommended for getting the latest version of Ansible.
Method 1: Install Ansible using apt
This method installs Ansible from the Ubuntu repositories.
- Update package lists:
1
sudo apt update
- Install software-properties-common (if not already installed):
1
sudo apt install software-properties-common -y
- Add the Ansible PPA (Personal Package Archive): This ensures you get a more recent version of Ansible than what might be in the default repositories.
1
sudo apt-add-repository ppa:ansible/ansible -y
- Install Ansible:
1
sudo apt install ansible -y
Method 2: Install Ansible using pip
(Recommended)
This method installs Ansible using Python’s package installer, which often provides the latest version.
- Update package lists and install Python 3 and pip:
1 2
sudo apt update sudo apt install python3 python3-pip git -y
- Install Ansible using pip:
1
pip3 install ansible
Verifying Ansible Installation
After installation, verify that Ansible is correctly installed and accessible.
- Check Ansible version:
1
ansible --version
- Test Ansible connectivity to localhost: This command uses the
ping
module to ensure Ansible can run basic tasks.1
ansible localhost -m ping
Expected output:
1 2 3 4
localhost | SUCCESS => { "changed": false, "ping": "pong" }
If you see a “pong” response, Ansible is successfully installed and functioning on your control node.