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
Enter fullscreen mode Exit fullscreen mode

RHEL/CentOS

$ sudo yum install ansible
Enter fullscreen mode Exit fullscreen mode

Ubuntu

Add the PPA to your system:

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

Install Ansible:

$ sudo apt-get install ansible
Enter fullscreen mode Exit fullscreen mode

Debian

Add the PPA to your system:

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

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
Enter fullscreen mode Exit fullscreen mode

Install Ansible:

$ sudo apt-get install ansible
Enter fullscreen mode Exit fullscreen mode

MacOS

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

Arch Linux

$ sudo pacman -S ansible
Enter fullscreen mode Exit fullscreen mode

Installing with pip

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

MacOS

$ sudo easy_install pip
Enter fullscreen mode Exit fullscreen mode

Fedora

Python 2.x

$ sudo dnf upgrade python-setuptools
$ sudo dnf install python-pip python-wheel
Enter fullscreen mode Exit fullscreen mode

Python 3.x

$ sudo dnf install python3 python3-wheel
Enter fullscreen mode Exit fullscreen mode

RHEL/CentOS

Python 2.x

$ sudo yum upgrade python-setuptools
$ sudo yum install python-pip python-wheel
Enter fullscreen mode Exit fullscreen mode

Python 3.x

sudo yum install python3 python3-wheel
Enter fullscreen mode Exit fullscreen mode

Ubuntu

Python 2.x

$ sudo apt-get install python-pip
Enter fullscreen mode Exit fullscreen mode

Python 3.x

$ sudo apt-get install python3-pip
Enter fullscreen mode Exit fullscreen mode

Arch Linux

Python 2.x

$ sudo pacman -S python2-pip
Enter fullscreen mode Exit fullscreen mode

Python 3.x

$ sudo pacman -S python-pip
Enter fullscreen mode Exit fullscreen mode

Once pip is installed you can install Ansible:

$ pip install ansible --user
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Creating a virtual environment for Ansible 2.6:

$ virtualenv ansible2.6
Enter fullscreen mode Exit fullscreen mode

Activate the ansible2.6 environment:

$ source ansible2.6/bin/activate
Enter fullscreen mode Exit fullscreen mode

Now install Ansible 2.6 in the virtual environment:

$ pip install ansible==2.6
Enter fullscreen mode Exit fullscreen mode

To deactivate an environment just run deactivate:

$ deactivate
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Top comments (0)