Sobes.tech
Junior

How to properly install Ansible?

sobes.tech AI

Answer from AI

The installation of Ansible depends on the operating system.

For Linux (the most common option for the Ansible controller):

Use the package manager.

  • Debian/Ubuntu:

    # Update package list
    sudo apt update
    # Install Ansible
    sudo apt install ansible
    
  • CentOS/RHEL/Fedora:

    # Enable EPEL repository (if needed)
    sudo yum install epel-release
    # Or for Fedora
    # sudo dnf install epel-release
    # Install Ansible
    sudo yum install ansible
    # Or for Fedora
    # sudo dnf install ansible
    

For macOS:

Use Homebrew.

# Install Homebrew (if not installed)
#/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install Ansible using pip in a virtual environment
brew install ansible

For Windows:

Ansible does not support Windows as a control node. To manage Windows hosts, Ansible must be installed on Linux/macOS/WSL. There are workarounds using WSL (Windows Subsystem for Linux), but these are not native solutions.

Alternative methods:

  • Installation via pip (recommended for isolation and version management, especially on macOS):
    # Install pip (if not installed)
    # sudo apt install python3-pip (for Debian/Ubuntu)
    # sudo yum install python3-pip (for CentOS/RHEL/Fedora)
    # Install venv (for creating virtual environments)
    # sudo apt install python3-venv (for Debian/Ubuntu)
    # sudo yum install python3-venv (for CentOS/RHEL/Fedora)
    # Create a virtual environment
    python3 -m venv ~/.ansible-venv
    # Activate the virtual environment
    source ~/.ansible-venv/bin/activate
    # Install Ansible
    pip install ansible
    # Deactivate the virtual environment (to exit)
    # deactivate
    
    This method allows installing Ansible in an isolated environment, without affecting system Python packages. Recommended for development and testing.

Basic check of installation:

After installation, verify the Ansible version to ensure successful installation.

# Check Ansible version
ansible --version

The output should contain information about the Ansible version, Python, and other dependencies.

Additional packages:

Some Ansible modules may require additional Python packages (e.g., paramiko for SSH, python-jenkins for Jenkins integration, etc.). These are usually installed via pip inside the virtual environment or system-wide, depending on the installation method.

# Example of installing paramiko
pip install paramiko

For managing certain cloud providers or services, additional Ansible Collection modules may be needed, which are installed using ansible-galaxy.

# Example of installing AWS collection
ansible-galaxy collection install amazon.aws