DEV Community

Enda
Enda

Posted on

How to Install Ansible

Original post: https://endaphelan.me/programming/guides/ansible/installing-ansible

Ansible is compatible with any machine running Linux or MacOS (sorry Windows users!). Before proceeding with this guide it is a requirement that you have Python 2 (version 2.7+) or Python 3 (version 3.5+) installed.

The simplest way to install Ansible is by using the default package manager for your operating system.

Fedora

$ sudo dnf install ansible

RHEL/CentOS

$ sudo yum install ansible

Ubuntu

Add the PPA to your system:

$ sudo apt-get install software-properties-common
$ sudo apt-add-repository --yes --update ppa:ansible/ansible

Install Ansible:

$ sudo apt-get install ansible

Debian

Add the PPA to your system:

$ echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main" >> /etc/apt/sources.list

Now add the PPA to a list of trusted sources and update the system:

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
$ sudo apt-get update

Install Ansible:

$ sudo apt-get install ansible

MacOS

See Installing with pip below for instructions on how to install Ansible on MacOS.

Arch Linux

$ sudo pacman -S ansible

Installing with pip

pip is Python's package manager. We will need to install in order to use it.

MacOS

$ sudo easy_install pip

Fedora

Python 2.x

$ sudo dnf upgrade python-setuptools
$ sudo dnf install python-pip python-wheel

Python 3.x

$ sudo dnf install python3 python3-wheel

RHEL/CentOS

Python 2.x

$ sudo yum upgrade python-setuptools
$ sudo yum install python-pip python-wheel

Python 3.x

sudo yum install python3 python3-wheel

Ubuntu

Python 2.x

$ sudo apt-get install python-pip

Python 3.x

$ sudo apt-get install python3-pip

Arch Linux

Python 2.x

$ sudo pacman -S python2-pip

Python 3.x

$ sudo pacman -S python-pip

Once pip is installed you can install Ansible:

$ pip install ansible --user

Installing a Specific Version of Ansible

If you are installing the latest version of Ansible then it is recommended to use the default package manager for your operating system.

Sometimes we need to install older versions. For this we can also use pip:

$ pip install ansible==2.6 --user

Installing Multiple Versions

We can use virtualenv to create and manage multiple isolated Python environments. This can be installed using pip:

$ pip install virtualenv --user

Creating a virtual environment for Ansible 2.6:

$ virtualenv ansible2.6

Activate the ansible2.6 environment:

$ source ansible2.6/bin/activate

Now install Ansible 2.6 in the virtual environment:

$ pip install ansible==2.6

To deactivate an environment just run deactivate:

$ deactivate

We can repeat the steps above to create another virtual environment for Ansible 2.7:

$ virtualenv ansible2.7
$ source ansible2.7/bin/activate
$ pip install ansible==2.7

Top comments (0)