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
-
Update the package list:
sudo apt update
-
Install the software-properties-common package:
sudo apt install software-properties-common
-
Add the Ansible PPA (Personal Package Archive):
sudo add-apt-repository --yes --update ppa:ansible/ansible
-
Install Ansible:
sudo apt install ansible
-
Verify the installation:
ansible --version
Installing on CentOS/RHEL
-
Enable the EPEL repository:
sudo yum install epel-release
-
Install Ansible:
sudo yum install ansible
-
Verify the installation:
ansible --version
Installation on macOS
Using Homebrew
-
Install Homebrew if you haven't already:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
-
Install Ansible:
brew install ansible
-
Verify the installation:
ansible --version
Installation on Windows
Using Windows Subsystem for Linux (WSL)
-
Enable WSL:
- Open PowerShell as Administrator and run:
wsl --install
- Open PowerShell as Administrator and run:
-
Install a Linux distribution from the Microsoft Store (e.g., Ubuntu).
-
Open the installed Linux distribution and update the package list:
sudo apt update
-
Install Ansible:
sudo apt install ansible
-
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.
Ansible: From Beginner to Advanced
Module 1: Introduction to Ansible
Module 2: Ansible Basics
Module 3: Playbooks
- Introduction to Playbooks
- Writing Your First Playbook
- Playbook Structure
- Variables and Facts
- Conditionals and Loops
Module 4: Roles
Module 5: Advanced Playbook Techniques
Module 6: Ansible Galaxy
Module 7: Ansible Tower
- Introduction to Ansible Tower
- Installing Ansible Tower
- Using Ansible Tower
- Managing Projects and Inventories