Install Ansible on MacOS, Windows, Ubuntu(debian) and Fedora(rpm) - Part 1

Thinking about Ansible as your configuration management tool, Great choice, of course, Ansible has a lot to offer and also a lot to learn to use effectively. Today’s article is your first step to Ansible!

In this tutorial,, we will dive together into Ansible's installation process on different platforms.

Ansible installation on Ubuntu,Limux mint, Febdora, CentOS, MacOS, Windows

Table of Content

  1. Brief Intro to Ansible
  2. Prerequisites
  3. SSH key generation
  4. RPM-based Installation
  5. Debian-based installation (Ubuntu/Linux Mint) 18.04/20.04/22.04 LTS
  6. Monterey macOS installation (using brew as well as without brew)
  7. Installation on windows using powershell
  8. Possible issues
  9. Verify Ansible installation by running ad-hoc command
  10. Conclusion

1. Brief Intro to Ansible

Ansible is an automation tool that can be used to enable users to have their servers configured automatically and scalably by writing minimal scripts. Imagine having one script that can configure 10 or 1000 servers in parallel without having to be manually helped or supervised by an IT specialist. Can you imagine the possibilities!

Ansible has 3 Main components :

  1. Playbook: Where your ansible configuration scripts is placed
  2. Inventory : A place to set your instances IPs and other details necessary for the ssh process
  3. Sever : A running machine with ansible

2. Prerequisites

Ansible controller nodes and ansible hosts

Control Node Ansible Hosts
1. The Machine that has ansible installed on it and controls ansible hosts The Machine that is controlled and managed by Ansible
2. Can be either a local machine or a dedicated server (AWS EC2 instance for example) Should be able to be ssh connected to the control node
3. You need either root access or a user with Sudo privileges Can be one machine or multiple machines
4. Will need to have ssh key pairs to connect to other machines (explained in next section ) Each host's Public IP address is needed

3. SSH key generation

ssh-keygen copy from ansible controller node to hosts

  1. Create RSA key pair using :
1ssh-keygen -C "Comment" 
  1. It will ask for the password or else you could keep the password blank also. But remember to take note of the location where the ssh keys will be generated.
 1Generating public/private RSA key pair.
 2Enter file in which to save the key (/home/vagrant/.ssh/id_rsa): 
 3Enter passphrase (empty for no passphrase): 
 4Enter same passphrase again: 
 5Your identification has been saved in /home/vagrant/.ssh/id_rsa.
 6Your public key has been saved in /home/vagrant/.ssh/
 7The key fingerprint is:
 8SHA256:LWGasiSDAqf8eY3pz5swa/nUl2rWc1IFgiPuqFTYsKs vagrant@amaster
 9The key's randomart image is:
10+---[RSA 2048]----+
11|          .      |
12|   .   . o . .   |
13|. . = . + . . .  |
14|o+ o o = o     . |
15|+.o = = S .   .  |
16|. .*.++...  ..   |
17|  ooo*.o ..o.    |
18| E .oo* .oo+ .   |
19|    .oo*+.  +    |
  1. Copy ssh key to your remote server :
1 ssh-copy-id username@host 

(Note- Please replace the username and host)

  1. Accept connection : Now the Key is added to your remote machine

4. RPM based Installation(Fedora/CentOS/RedHat)

The following installation instructions should work on RPM based linux distros .i.e. Fedora, CentOS and RedHat


  1. If running Fedora distro, first update the yum repository :
1yum update  

Run the following command to install Ansible from the yum repository -

1sudo yum install ansible 


  1. Use the following command for installing Ansible on CentOS. The command will first update yum repository and then it will perform Ansible installation -
1sudo yum -y update &&  sudo yum -y install epel-repo && sudo yum -y update && sudo yum -y install ansible

Other RPM-based distros- Use the following command to build an RPM distribution on your own -

1yum install rpm-build make asciidoc git python-setuptools python2-devel
2git clone git:// --recursive
3cd ./ansible
4make rpm
5sudo rpm -Uvh ./rpm-build/ansible-*.noarch.rpm

yum install rpm-build make asciidoc git python-setuptools python2-devel

sudo yum install ansible

Each of the above commands will do the following tasks -

  • Installs dependencies like git and make
  • Clone the ansible repo with git
  • Make rpm artifact
  • Install artifact

5. Debian based installation (Ubuntu/Linux Mint) 18.04/20.04/22.04 LTS

  1. Add an ansible repository to the apt-get package manager -
1sudo apt-get install software-properties-common && sudo apt-add-repository ppa:ansible/ansible 

Ubuntu install software-properties-common and ansible repository ppa:ansible/ansible

  1. Update apt-get package manager and install Ansible -
1sudo apt-get update && sudo apt-get install ansible

Install ansible sudo apt-get install ansible

Verify the ansible installation on Ubuntu by running ansible --version

Verify ansible installation by running the ansible --version command

6. MacOS installation (using brew as well as without brew)

6.1 Anisble installation using brew

  1. Install the brew onto your macOS (If you do not have already installed)
1/bin/bash -c "$(curl -fsSL"
  1. Install Ansible
1brew install ansible

6.2 Without Using brew

  1. Check if Xcode is installed on your machine
1xcode-select -p 

If no error is received then Xcode is installed and proceed to the next step otherwise you need install Xcode

  1. Check if python is installed (It’s by default installed on the new version of macOS but in-case if python is missing then install the python)
1python --version 


1python3 --version 

If you have already installed python onto your machine then it should return you back with the version -

1Python 2.X.X 


1Python 3.X.X
  1. To Install then ansible use
1sudo easy_install pip
2sudo pip install ansible --quiet 

7. Installation on windows using powershell

To install Ansible on Windows you need to run Windows Subsystem for Linux (WSL) which can be used to deploy a linux distro (ubuntu by default) to enable installation of ansible.

  1. Install WSL from PowerShell
1wsl --install  

If you do not have wsl installed then refer to the following instructions

List the wsl versions -

1wsl --list --online 

Then select a distro and run

1wsl --install -d (Distro Name)

Set the username and password for the Linux subsystem after installing the wsl -

1Enter new UNIX username: your-username
2New password: your-password
3Retype new password: your-password 
  1. Install the Ansible based on your Linux subsystem distribution. If you are using debian based Linux the follow these installation instructions or if you are using rpm based linux then follow these installation instructions

8. Possible issues which you might face during the installation

8.1 AttributeError: 'module' object has no attribute '_vendor'

During the installation of Ansible on MacOS, you might face the error _AttributeError: 'module' object has no attribute 'vendor'.

How to troubleshoot?- You need to install pip with python and then install ansible with pip

1sudo easy_install pip || sudo python -m ensure pip  
2sudo pip install ansible 

It might be possible that during the installation of Ansible on Fedora you might end up with the error Error: Cannot retrieve Metalink for repository: epel. Please verify its path and try again -

How to troubleshoot?- Build an RPM on your own from Ansible’s repo

1yum install rpm-build make asciidoc git python-setuptools python2-devel
2git clone git:// --recursive && cd ./ansible
3make rpm && sudo rpm -Uvh ./rpm-build/ansible-*.noarch.rpm 

8.3 Error during the installation of Ansible on Debian

The repository ' kinetic Release' does not have a Release file.

How to troubleshoot?- Add the

1sudo apt-add-repository --remove ppa:ansible/ansible
2sudo apt-get update && sudo apt-get install ansible --allow-unauthenticated 

9. Verify Ansible installation by running adhoc command

Irrespective of the base operating system you verify the installation of ansible by running adhoc commands.

For example -

  1. Verify the Disk usage of your machine after the ansible installation -
1ansible localhost -a "df -h" -u root
  1. Find the total uptime of the host machine -
1 ansible localhost -a "uptime" -u root 

10. Conclusion

I hope this tutorial can help you to validly install ansible on your own machine and start your learning with Ansible, in the following article we look into How to write an ansible playbook?

Posts in this Series