To install Ansible on Ubuntu, you can use the official Ubuntu repository with sudo apt update && sudo apt install ansible, or install the latest version via Python’s pip. This guide walks you through both methods, explains prerequisites, and answers common setup questions.
What Is Ansible and Why Use It?
Ansible is an open-source automation tool used for configuration management, application deployment, and task automation. It is agentless, meaning you do not need to install any software on the machines you manage—only on the control node (the machine from which you run commands). Ansible uses SSH to connect to remote hosts and executes tasks defined in YAML playbooks. It is popular because it is simple to learn, uses a declarative language, and requires no daemons or databases.
Prerequisites for Installing Ansible
Before you begin, ensure your Ubuntu system meets these requirements:
- Ubuntu 20.04 LTS or newer (though older versions may work).
- A user account with
sudoprivileges. - Python 3 and pip (usually preinstalled on Ubuntu).
- SSH client installed if you plan to manage remote hosts.
You also need network access to the Ubuntu repositories or PyPI (Python Package Index) to download the package.
Method 1: Install Ansible from Ubuntu Repository
This is the simplest method and works for most users. The version in the repository may be older than the latest release, but it is stable and receives security updates.
- Open a terminal (Ctrl+Alt+T).
- Update your package list:
sudo apt update - Install Ansible:
sudo apt install ansible - Verify the installation:
ansible --version
You should see output with the Ansible version number and its configuration details. If you see an error, make sure your package list is updated and that you have internet access.
Method 2: Install Ansible with pip (Latest Version)
If you need the newest features or a specific version, installing via pip is recommended. This method also lets you install Ansible in a virtual environment to avoid conflicts with system packages.
- Install pip for Python 3:
sudo apt install python3-pip - Install Ansible globally:
sudo pip3 install ansible - Or install in a virtual environment (recommended):
- Create a venv:
python3 -m venv ansible-env - Activate it:
source ansible-env/bin/activate - Install Ansible:
pip install ansible
- Create a venv:
- Verify:
ansible --version
Note: If you install with pip, you may need to use pip3 instead of pip depending on your system. Also, using a virtual environment prevents package conflicts with the system’s Python.
Choosing Between apt and pip
Which method you choose depends on your needs:
- apt: Easier, integrates with system package management, and is ideal for most users who just want a working Ansible.
- pip: Gives you the latest release, allows version pinning, and is better for developers who need new features or specific versions.
If you are unsure, start with the apt version. You can always install the pip version later, but avoid mixing both to prevent conflicts.
Post-Installation: Basic Configuration
After installation, you need to set up an inventory file that lists the hosts Ansible will manage. The default inventory is at /etc/ansible/hosts. You can edit it with sudo nano /etc/ansible/hosts and add your server IPs or hostnames. For example:
[webservers] 192.168.1.10 192.168.1.11
Then test connectivity with ansible all -m ping. This will try to connect via SSH to all hosts in the inventory. You may need to set up SSH keys to avoid password prompts.
Common Installation Issues and Fixes
- “Package ‘ansible’ has no installation candidate”: This usually means your package list is outdated. Run
sudo apt updateand try again. - Permission denied when running pip: Use
sudoor install in a virtual environment. - SSH connection errors: Ensure SSH is installed on the control node (
sudo apt install openssh-client) and that the remote hosts have SSH enabled. - Ansible command not found: If you installed via pip in a virtual environment, activate it first. If installed globally, check that the bin directory is in your PATH.
Frequently Asked Questions
Do I need to install Ansible on every server I manage?
No. Ansible is agentless. You only install it on the control node (your local machine or a dedicated server). The managed nodes only need SSH and Python 2.6 or later (or Python 3.5+ for Ansible 2.5+).
Can I install Ansible on Ubuntu without sudo?
Yes, if you use pip and install in a user location or a virtual environment. For example, pip install --user ansible installs it in your home directory. However, you will need sudo for system-wide apt installation.
How do I upgrade Ansible?
If installed via apt, run sudo apt update && sudo apt upgrade ansible. If installed via pip, run pip install --upgrade ansible (or sudo pip3 install --upgrade ansible).
What is the difference between Ansible and Ansible Core?
Ansible Core is the command-line tool and the engine that runs playbooks. Ansible (the full package) includes a curated collection of modules and plugins. When you install ansible via pip, you get both. The apt package also includes the full collection.
Is Ansible free to use?
Yes, Ansible is open-source and free to use. Red Hat offers Ansible Automation Platform, which adds enterprise features and support, but the core tool is free.
Can I use Ansible on Windows?
Ansible control node runs on Linux, macOS, and Windows Subsystem for Linux (WSL). It cannot run natively on Windows as a control node, but it can manage Windows hosts if you configure WinRM.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Fix Deleted Printer Keeps Reappearing in Windows 10
- How to Bid Software Projects: A Practical Guide
- iPad Tips and Tricks to Turn You Into a Power User
- Fix ‘Some settings are managed by your organization’ on Windows 10
- iPhone Random Vibrations: Causes & Fixes
- iPhone Sound Not Working? 7 Fixes to Try Now