In this video, Jesse Keating demonstrates how to install Ansible on a Linux operating system. Learn a few methods for installing Ansible to match the needs of a diverse user base.
- [Instructor] Ansible needs to be explicitly installed on the control machine, which is the machine that will be processing all of the task execution directions. Ansible requires Python 2.6 or later with support for Python 3 coming soon. Use of Microsoft Windows as a control machine is not supported. However, most other operating systems are. I'll be using Fedora 25, a Linux distribution with a supported version of Python to demonstrate the installation of Ansible.
The Ansible project provides detailed installation directions on their website. Since I'm using Fedora, I'll use the built-in package manager dnf to install Ansible. Using dnf, I can search to see if Ansible is available for install. There are a few results and the first result is the one that we want, simply Ansible. I'll install it. Dnf determines which packages should be included to satisfy Ansible requirements.
These requirements are based on the default of using SSH to communicate with remote target hosts. I'll accept the install of Ansible with its dependencies with Y. Now I can check the availability of Ansible using the which command. I can see that it is available at usr/bin/ansible. I can check which version is installed by using the version argument with the Ansible executable.
This output shows that I've installed Ansible version 18.104.22.168 and further, that there is a configuration file in use at etc/ansible/ansible/cfg and that the module search path is the default. Using tab completion, I can see that there are multiple Ansible-based commands available. Alternatively, I can install Ansible via Python pip in a Python virtual environment. This is useful if I want to make use of multiple versions of Ansible or if I'm operating in an environment where I do not have rights to install things in the system path.
First, I'll remove the system installed Ansible. A quick check of which shows that Ansible is no longer available to me. A Python virtual environment creates an isolated Python environment in the directory of my choosing. I'll need to make sure I have the virtual env utility installed. I also know that to install Ansible via pip, I'll need to install some development tools to build parts of the Python libraries, specifically the GCC Compiler and the Open SSL development headers.
If you are working with a system where you do not have root access, you can ask your administrator to install these basic tools for you. Now I'll create a new Python virtual environment named Ansible and place it in my home directory where I have write access to the file system. Next, I need to activate this environment so that my execution path is set correctly. My shell prompt has changed slightly to indicate that I'm now set to work from the Ansible virtual environment.
I can verify this by checking the location of the pip command which is used to install Python packages. Now I can search for Ansible using pip. There are quite a lot of results. Many things are available to work with Ansible, but I'm interested in the core of Ansible itself so I'll pipe the output into less and then search for a line that starts with Ansible with a trailing slash and here I quickly find what I'm looking for.
Alternatively, I can browse to the Python website and from here, I can search for Ansible. The first result is the package I'm looking for and I can get more information about it by clicking on it. Now I'll ask pip to install this with the install directive. At this point, Ansible should once more be available to me and I'll verify this with the which command.
This time, I see it available inside of the virtual environment. I'll check the version once more and see once again, I have version 22.214.171.124. But this time, there is not a configuration file in use as I did not have write access to the etc path.
- What is Ansible?
- Working with hosts and variables
- Controlling task and play behavior
- Coordinating complicated sets of actions
- Managing system configurations
- Reacting to configuration changes
- Repeating a task across a fleet
- Managing extensions in Ansible