Table of Contents
Go from Ansible beginner to Ansible pro with this full video course.
Note: this guide is for installing Ansible on your local machine. You can manage remote machines using Ansible without installing Ansible on them.
The two best methods for installing Ansible on Ubuntu Linux 18.04 (Bionic Beaver) are:
- Using the
apt
package manager (best for beginners) - Using Python
pip
(best for advanced users)
The official documentation states that their preferred method for installing Ansible on Ubuntu is using the apt
package manager. I believe that installing via apt
is the best method for beginners, but for advanced users I recommend installing Ansible via pip
.
The main difference between the two methods is that using pip
will give you more control over the Python version Ansible uses as well as any Python packages that Ansible depends on. This is especially useful if you’re using a version manager like asdf
, which I highly recommend.
How to install Ansible on Ubuntu 18.04 using apt
Assuming that you have a fresh install of Ubuntu 18.04, you can get Ansible installed by running the following 4 commands:
sudo apt-get update
sudo apt-get install software-properties-common
sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt-get install ansible
After the installation has finished, you can confirm that Ansible has installed correctly by running ansible --version
:
$ which ansible
/usr/bin/ansible
$ ansible --version
ansible 2.7.5
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/ubuntu/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.15rc1 (default, Nov 12 2018, 14:31:15) [GCC 7.3.0]
If ansible --version
runs successfully, congratulations! You now have Ansible’s power at your fingertips and you’re ready to start managing your servers.
How to install Ansible on Ubuntu 18.04 using Python pip
Confirm that pip
is installed and upgrade it to the latest version
First, ensure that Python pip
is installed on your system. You can check if pip
is in your PATH
by running which pip
. If pip
is found, run pip --version
to confirm that everything is working as expected:
$ which pip
/home/ubuntu/.asdf/shims/pip
$ pip --version
pip 18.1 from /home/ubuntu/.asdf/installs/python/2.7.15/lib/python2.7/site-packages/pip (python 2.7)
I use asdf
to manage the Python versions on my system (and I suggest you do too). pip
is automatically installed along with asdf
Python installations.
If pip
isn’t on your system and you’re using the default Python version on your system, you can usually install pip
by running sudo easy_install pip
.
I suggest running pip install --upgrade pip
to update pip
to the latest version before installing Ansible:
$ pip install --upgrade pip
Requirement already up-to-date: pip in ./.asdf/installs/python/2.7.15/lib/python2.7/site-packages (18.1)
Install Ansible
Assuming pip
is installed and working, installing Ansible is as simple as running pip install ansible
:
$ pip install ansible
Collecting ansible
...
Successfully installed MarkupSafe-1.1.0 PyYAML-3.13 ansible-2.7.5 asn1crypto-0.24.0 bcrypt-3.1.5 cffi-1.11.5 cryptography-2.4.2 enum34-1.1.6 idna-2.8 ipaddress-1.0.22 jinja2-2.10 paramiko-2.4.2 pyasn1-0.4.5 pycparser-2.19 pynacl-1.3.0 six-1.12.0
Confirm that ansible
is in your path and that it runs as expected:
$ asdf reshim python
$ which ansible
/home/ubuntu/.asdf/shims/ansible
$ ansible --version
ansible 2.7.5
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/ubuntu/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /home/ubuntu/.asdf/installs/python/2.7.15/lib/python2.7/site-packages/ansible
executable location = /home/ubuntu/.asdf/installs/python/2.7.15/bin/ansible
python version = 2.7.15 (default, Jan 9 2019, 10:53:46) [GCC 7.3.0]
If ansible --version
runs successfully, congratulations! You now have Ansible’s power at your fingertips and you’re ready to start managing your servers.