Installing Ansible - Ansible Documentation
Installing Ansible - Ansible Documentation
Installing Ansible
This page describes how to install Ansible on different platforms. Ansible is an agentless
automation tool that by default manages machines over the SSH protocol. Once installed,
Ansible does not add a database, and there will be no daemons to start or keep running. You
only need to install it on one machine (which could easily be a laptop) and it can manage an
entire eet of remote machines from that central point. When Ansible manages remote
machines, it does not leave software installed or running on them, so there’s no real question
about how to upgrade Ansible when moving to a new version.
Prerequisites
Control node requirements
Managed node requirements
Selecting an Ansible version to install
Installing Ansible on RHEL, CentOS, or Fedora
Installing Ansible on Ubuntu
Installing Ansible on Debian
Installing Ansible on Gentoo with portage
Installing Ansible on FreeBSD
Installing Ansible on macOS
Installing Ansible on Solaris
Installing Ansible on Arch Linux
Installing Ansible on Slackware Linux
Installing Ansible on Clear Linux
Installing Ansible with pip
Running Ansible from source (devel)
Finding tarballs of tagged releases
Ansible command shell completion
Installing argcomplete on RHEL, CentOS, or Fedora
Installing argcomplete with apt
Installing argcomplete with pip
Con guring argcomplete
Globally
Per command
argcomplete with zsh or tcsh
Ansible on GitHub
Prerequisites
Search this site
You install Ansible on a control node, which then uses SSH (by default) to communicate with
your managed nodes (those end devices you want to automate).
Currently Ansible can be run from any machine with Python 2 (version 2.7) or Python 3
(versions 3.5 and higher) installed. This includes Red Hat, Debian, CentOS, macOS, any of the
BSDs, and so on. Windows is not supported for the control node.
When choosing a control node, bear in mind that any management system bene ts from being
run near the machines being managed. If you are running Ansible in a cloud, consider running it
from a machine inside that cloud. In most cases this will work better than on the open Internet.
Note
macOS by default is con gured for a small number of le handles, so if you want to use 15
or more forks you’ll need to raise the ulimit with
sudo launchctl limit maxfiles unlimited . This command can also x any “Too many open
les” error.
Warning
Please note that some modules and plugins have additional requirements. For modules
these need to be satis ed on the ‘target’ machine (the managed node) and should be listed
in the module speci c docs.
On the managed nodes, you need a way to communicate, which is normally SSH. By default
this uses SFTP. If that’s not available, you can switch to SCP in ansible.cfg
(../reference_appendices/con g.html#ansible-con guration-settings). You also need Python 2
(version 2.6 or later) or Python 3 (version 3.5 or later).
Note
If you have SELinux enabled on remote nodes, you will also want to install libselinux-
python on them before using any copy/ le/template related functions in Ansible. You
can use the yum module (../modules/yum_module.html#yum-module) or dnf module
(../modules/dnf_module.html#dnf-module) in Ansible to install this package on remote
systems that do not have it.
By default, Ansible uses the Python interpreter located at /usr/bin/python to run its
modules. However, some Linux distributions may only have a Python 3 interpreter
installed to /usr/bin/python3 by default. On those systems, you may see an error like:
Install the latest release with your OS package manager (for Red Hat Enterprise Linux
(TM), CentOS, Fedora, Debian, or Ubuntu).
Install with pip (the Python package manager).
Install from source to access the development ( devel ) version to develop or test the latest
features.
Note
You should only run Ansible from devel if you are actively developing content for Ansible.
This is a rapidly changing source of code and can become unstable at any point.
Ansible creates new releases two to three times a year. Due to this short release cycle, minor
bugs will generally be xed in the next release versus maintaining backports on the stable
branch. Major bugs will still have maintenance releases when needed, though these are
infrequent.
RPMs for RHEL 7 and RHEL 8 are available from the Ansible Engine repository
(https://access.redhat.com/articles/3174981).
To enable the Ansible Engine repository for RHEL 8, run the following command:
To enable the Ansible Engine repository for RHEL 7, run the following command:
RPMs for currently supported versions of RHEL, CentOS, and Fedora are available from EPEL
(https://fedoraproject.org/wiki/EPEL) as well as releases.ansible.com
(https://releases.ansible.com/ansible/rpm).
Ansible version 2.4 and later can manage earlier operating systems that contain Python 2.6 or
higher.
You can also build an RPM yourself. From the root of a checkout or tarball, use the make rpm
command to build an RPM you can distribute and install.
To con gure the PPA on your machine and install Ansible run these commands:
Note
Debian/Ubuntu packages can also be built from the source checkout, run:
$ make deb
You may also wish to run from source to get the development branch, which is covered below.
Note
To install the newest version, you may need to unmask the Ansible package prior to emerging:
or:
Older versions of FreeBSD worked with something like this (substitute for your choice of
package manager):
The instructions can be found in Installing Ansible with pip. If you are running macOS version
10.12 or older, then you should upgrade to the latest pip to connect to the Python Package
Index securely.
# pkgadd -d http://get.opencsw.org/now
# /opt/csw/bin/pkgutil -i ansible
$ pacman -S ansible
The AUR has a PKGBUILD for pulling directly from GitHub called ansible-git
(https://aur.archlinux.org/packages/ansible-git).
# sqg -p ansible
Build and install packages from a created queue le (answer Q for question if sbopkg should
use queue or package):
If you are installing on macOS Mavericks (10.9), you may encounter some noise from your
compiler. A workaround is to do the following:
$ python -m virtualenv ansible # Create a virtualenv if one does not already exist
$ source ansible/bin/activate # Activate the virtual environment
$ pip install ansible
Note
Running pip with sudo will make global changes to the system. Since pip does not
coordinate with system package managers, it could make changes to your system that
leaves it in an inconsistent or non-functioning state. This is particularly true for macOS.
Installing with --user is recommended unless you understand fully the implications of
modifying global les on the system.
Note
You should only run Ansible from devel if you are actively developing content for Ansible.
This is a rapidly changing source of code and can become unstable at any point.
Note
If you want to use Ansible Tower as the control node, do not use a source installation of
Ansible. Please use an OS package manager (like apt or yum ) or pip to install a stable
version.
Once git has cloned the Ansible repository, setup the Ansible environment:
Using Bash:
$ source ./hacking/env-setup
Using Fish:
$ source ./hacking/env-setup.fish
$ source ./hacking/env-setup -q
If you don’t have pip installed in your version of Python, install it:
Ansible also uses the following Python modules that need to be installed [1]:
Once running the env-setup script you’ll be running from checkout and the default inventory
le will be /etc/ansible/hosts . You can optionally specify an inventory le (see How to build
your inventory (../user_guide/intro_inventory.html#inventory)) other than
/etc/ansible/hosts :
You can read more about the inventory le at How to build your inventory
(../user_guide/intro_inventory.html#inventory).
For more information about installing and con guration see the argcomplete documentation
(https://argcomplete.readthedocs.io/en/latest/).
On Fedora:
There are 2 ways to con gure argcomplete to allow shell completion of the Ansible command
line utilities: globally or per command.
Globally
$ sudo activate-global-python-argcomplete
This will write a bash completion le to a global location. Use --dest to change the location.
Search this site
Per command
If you do not have bash 4.2, you must register each script independently.
You should place the above commands into your shells pro le le such as ~/.profile or
~/.bash_profile .
Ansible on GitHub
You may also wish to follow the GitHub project (https://github.com/ansible/ansible) if you have
a GitHub account. This is also where we keep the issue tracker for sharing bugs and feature
ideas.
See also
irc.freenode.net (http://irc.freenode.net)