Installing AnsibleLast updated: 15 October 2020
Ansible is installed on a control node, which is the machine that communicates with the end devices you want to automate, so called managed nodes.
Ansible is installed on a control node, which is the machine that communicates with the end devices you want to automate, so called managed nodes.
In this section we summarize important system prerequisites
Ansible can be run from any machine with Python version 2 (2.7+) or Python version 3 (3.5+).This includes but is not limited to Debian, macOS, CentOS, RHEL, or any of the Berkeley Software Distributions.
When implementing a Windows machine as control node Windows Subsystem for Linux must be used, as Ansible is not natively supported in python on Windows
When choosing a control node, it is important to bear in mind that the Ansible platform greatly benefits from being run near the managed nodes. If you are running Ansible in a cloud environment, consider running a machine within the same environment, instead of using a local workstation.
Some modules and plugins might have additional requirements. These requirements are listed in the module specific documentation.
A managed node must be capable of functioning as an SSH-server.
Furthermore, the nodes also need python. By default ansible uses python 2 (version 2.6+) but ansible can also use python 3 (version 3.5+). When using python 3 you need to set the ansible_python_interpreter inventory variable.
If the prospect node has selinux installed it is recommend that libselinux-python is also installed as some command can otherwise be interfered with by selinux.
Which Ansible version to install is based on your particular needs and the environment you want to automate. You can choose any of the following ways to install Ansible:
The development version of Ansible should only be used if you are actively devolving content. The source code of the development version is rapidly changing, which can result in instability.
In this section we will explian step by step how to install ansible on serveral different operation systems.
if your operating system is not listed, please refer to the Ansible documentation
sudo dnf install ansible
On RHEL and CentOS:
sudo yum install ansible
To configure and install Ansible, you have to run these commands:
sudo apt update
sudo apt install software-properties-common
sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt install ansible
On older versions of Ubuntu you may want to use apt-get instead of apt.
While installing Ansible from the source makes it difficult to uninstall it. Ansible copies files right into the right directory, so it is difficult to track which files were created. By building a .deb packages, you can easily uninstall Ansible.
Installing Ansible from a .deb package requires the same packages as installing it from the source.
The following commands will install and build Ansible from a Debian package:
sudo apt-get update
sudo apt-get install build-essential git python-pip python-dev libffi-dev libssl-dev asciidoc devscripts debhelper cdbs
git clone git://github.com/ansible/ansible.git --recursive
cd ansible
make deb
Once the last command is done, you have to locate the built Debian package. This can be done with the following command:
find . -name "*.deb" ./deb-build/unstable/ansible_2.2.0-0.git201607051907.d0ccedc.devel~unstable_all.deb
Before you can install this package, you’ll need to install some packages that Ansible needs by running the following command:
sudo apt-get install python-jinja2 python-paramiko sshpass python-markupsafe
Once the packages are installed, you can install Ansible from the Debian package you just build:
sudo dpkg -i ./deb-build/unstable/ansible_2.2.0-0.git201607051907.d0ccedc.devel~unstable_all.deb
You can now verify that Ansible is installed by checking the version, with ansible --version.Ansible works with different versions of Python, FreeBSD has these different packages for each Python version. To install Python you can use this:
sudo pkg install py27-ansibleOr:sudo pkg install py36-ansible
The specific version of Ansible can be chosen, i.e. ansible25.
Older versions of FreeBSD works with this (depends of your choice of package manager):
sudo pgk install ansible
The preferred way to install Ansible on macOS is with Python Package manager (pip). To install Ansible with pip can be found in Installing Ansible with pip. If you running macOS version 10.12 or older, it is recommended to upgrade to the latest version of pip to connect to the Python Package Index securely.
Ansible can be installed with the Python Package manager. If pip isn't installed on your system, you can run the following commands:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py –user
Then install Ansible:
pip install --user ansibleRunning pip with sudo will make global changes to the system. Since pip does not coordinate with system package managers, it could make changes to system files, leaving the system in an inconsistent or non-functioning state.
This is particularly true for macOS. Installing with --user is recommended unless you fully understand the possible implications of modifying global system files.
Please make sure you have the latest version of pip before installing Ansible. If you have an older version of pip installed, you can upgrade with: pip install -U pip
On Fedora:
sudo dnf install python-argcomplete
On RHEL and CentOS:
sudo yum install epel-release
sudo yum install python-argcomplete
Using apt:
sudo apt install python-argcomplete
Using pip:
python -m pip install argcomplete
Global completion requires bash 4.2 or later
globally:
sudo activate-global-python-argcomplete
This will write a bash completion file to a global location. Use --destto change the location.
eval $(register-python-argcomplete ansible)
eval $(register-python-argcomplete ansible-config)
eval $(register-python-argcomplete ansible-console)
eval $(register-python-argcomplete ansible-doc)
eval $(register-python-argcomplete ansible-galaxy)
eval $(register-python-argcomplete ansible-inventory)
eval $(register-python-argcomplete ansible-playbook)
eval $(register-python-argcomplete ansible-pull)
eval $(register-python-argcomplete ansible-vault)
You should place the above commands into your shell profile files such as ~/.profileor ~/.bash_profile.