If you have a lot of hosts to manage, it’s time to automate configuration management by installing Ansible! Ansible is the most popular automation tool for managing configuration changes to your on-premises and cloud resources.
In this article, you will learn from scratch how to download and install an Ansible driver host on Ubuntu, RHEL, and macOS. You’ll also get off to a good start in executing your first commands!
This tutorial will use Ansible v2.9.20, but the process for configuring Ansible on a controller host should be almost identical for later versions.
Related: A Step-by-Step Guide to Getting Started With
Ansible on Windows Installing Ansible on
You can install Ansible on any *nix-based operating system. One of the most popular options is Ubuntu. Let’s start this tutorial and see a tutorial on how to make it happen.
If you want to set up Ansible on Ubuntu, this section will assume that you have an Ubuntu 18+ machine with Python2 or higher installed. This tutorial will use Ubuntu 18.04.5 LTS with Python3.
1. Connect to your future Ansible driver on an Ubuntu host with your favorite SSH client.
2. Ansible is stored as a package that can be downloaded and installed through the apt package manager. To ensure that apt can find the right source and download any dependent packages, run apt update.
The apt or apt-get command installs packages from apt software repositories configured in Ubuntu
3. Continue preparing apt to download and install Ansible by installing the software-properties-common package. sudo apt install software-properties-common
<img src="https://adamtheautomator.com/wp-content/uploads/2021/04/Untitled-2021-04-25T174852.113.png" alt="Installing the package using the apt command
4. Next, add the ansible/ansible personal package file (PPA) as a suitable repository. This repository is managed by Red Hat, not Ubuntu sources, so you have to add it manually.
5. Now, install the ansible package by running the apt install 6 command
. When you’re done, confirm that Ansible is installed by running the ansible -version command. If all is well ansible -version Install Ansible
Ubuntu is not the only operating system supported by Ansible. Red Hat Enterprise Linux (RHEL) or CentOS are also common options. Let’s start with RHEL.
If you plan to follow this section, make sure you have a RHEL version 8+ host (this tutorial will use RHEL 8.3 (Ootpa).
1. Connect to your RHEL host via SSH with your favorite SSH client.
2. Install python3-pip and python3 package with dnf. Ansible works with Python2, but this tutorial will use Python3 because Python2 will soon be considered legacy.
3. Install the Extra Packages for Enterprise Linux (EPEL) repository. The EPEL repository contains several system packages, including the Ansible package, which you will install in the next step.
4. Once you have installed the repository, install the Ansible package by referencing the required EPEL repository and the package name (ansible). The dnf utility will automatically download the latest version of Ansible.
5. Now, verify that Ansible has been successfully installed by running
Ansible Installation on CentOS
Rounding up *nix hosts, let’s get done with setting up Ansible on
If you plan to follow this section, make sure you have a CentOS 7+ host with Python2 or higher installed (this tutorial will use CentOS 7.9.2009 Core).
1. Connect to your CentOS host via SSH with your favorite SSH client
2. Install the Extra Packages for Enterprise Linux (EPEL) repository. The EPEL repository contains several system packages, including the Ansible package, which you will install in the next step.
The yum command installs and manages the software using Red Hat’s official software repositories, as well as other third-party repositories.
3. Once the repository is complete, install the Ansible package.
4. Now, confirm that Ansible is installed by running ansible -version.
Ansible on macOS
So far, you’ve learned how to set up Ansible on various Linux distributions. Let’s finish this tutorial by learning how to install Ansible on a Mac.
This section of the tutorial will focus on the popular macOS package manager called Homebrew. Homebrew is the easiest way to install Ansible on macOS. This tutorial will use Homebrew v3.0.7 on macOS Catalina.
If you want to learn how to install Ansible through the popular Python package manager pip, check out the Ansible pip package.
To install on
- Open Apple Terminal
- Run the following command to invoke Homebrew to download and install Ansible on your Mac
- Once completed, verify that Ansible is installed by running ansible -version.
Test Ansible by
running ad-hoc commands
Now that Ansible is installed, you’re not doing much good unless you actually use it! One of the easiest ways to get started with Ansible is to learn about ad hoc commands. Ad hoc commands are typically single-line commands that Ansible invokes on remote computers (or on the Ansible host in this example).
ad-hoc commands on
Windows hosts Run an ad-hoc command on the operating system of your choice using the -m switch. The -m switch specifies an Ansible module that contains several functionality.
One of the
simplest modules of Ansible is the ping module. This module tests connectivity between the Ansible driver and a host. If you do not have any remote hosts available, provide the name of the Ansible driver itself (localhost) to run the ping module.
If you succeed, you should see a green output indicating success!
In this tutorial, you learned how to set up the most widely used automation tool, Ansible, on Ubuntu, RHEL, CentOS, and macOS.
Now that you have a new Ansible controller host set up, what do you plan to manage with it?