In this section, we will cover the steps required to install Ansible on various operating systems. By the end of this module, you will have Ansible installed and ready to use on your machine.

Prerequisites

Before we begin, ensure you have the following:

  • A machine with a supported operating system (Linux, macOS, or Windows).
  • Administrative (root) access to the machine.

Installation on Linux

Installing on Ubuntu/Debian

  1. Update the package list:

    sudo apt update
    
  2. Install the software-properties-common package:

    sudo apt install software-properties-common
    
  3. Add the Ansible PPA (Personal Package Archive):

    sudo add-apt-repository --yes --update ppa:ansible/ansible
    
  4. Install Ansible:

    sudo apt install ansible
    
  5. Verify the installation:

    ansible --version
    

Installing on CentOS/RHEL

  1. Enable the EPEL repository:

    sudo yum install epel-release
    
  2. Install Ansible:

    sudo yum install ansible
    
  3. Verify the installation:

    ansible --version
    

Installation on macOS

Using Homebrew

  1. Install Homebrew if you haven't already:

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
  2. Install Ansible:

    brew install ansible
    
  3. Verify the installation:

    ansible --version
    

Installation on Windows

Using Windows Subsystem for Linux (WSL)

  1. Enable WSL:

    • Open PowerShell as Administrator and run:
      wsl --install
      
  2. Install a Linux distribution from the Microsoft Store (e.g., Ubuntu).

  3. Open the installed Linux distribution and update the package list:

    sudo apt update
    
  4. Install Ansible:

    sudo apt install ansible
    
  5. Verify the installation:

    ansible --version
    

Common Installation Issues and Troubleshooting

Issue: "ansible: command not found"

  • Solution: Ensure that Ansible is installed correctly and that the installation path is included in your system's PATH environment variable.

Issue: "No module named 'ansible'"

  • Solution: This error typically occurs if Ansible is not installed in the current Python environment. Ensure you are using the correct Python environment and that Ansible is installed.

Issue: "Failed to add the PPA"

  • Solution: Ensure that your system has internet access and that the software-properties-common package is installed.

Conclusion

In this section, we covered the steps to install Ansible on various operating systems, including Linux, macOS, and Windows. You should now have Ansible installed and ready to use. In the next section, we will explore the architecture of Ansible to understand how it works under the hood.

© Copyright 2024. All rights reserved