You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Before you can automate anything with Ansible, you need to install it on your control node --- the machine from which you will manage your infrastructure. This lesson covers installation methods, initial configuration, and running your first Ansible commands.
sudo access)The recommended way to install Ansible is via Python's package manager:
# Install Ansible (full package including community collections)
pip install ansible
# Or install just the core engine (lighter)
pip install ansible-core
Install from your OS package manager:
# Ubuntu / Debian
sudo apt update
sudo apt install ansible
# RHEL / CentOS / Fedora
sudo dnf install ansible
# macOS (Homebrew)
brew install ansible
For an isolated installation that does not conflict with system Python packages:
pipx install ansible
After installation, verify that Ansible is working:
ansible --version
Expected output:
ansible [core 2.16.x]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/user/.ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.12.x
Key information displayed:
| Field | Description |
|---|---|
| core version | The Ansible core engine version |
| config file | Which configuration file is active |
| python version | The Python interpreter Ansible is using |
Ansible looks for its configuration file in the following order (first match wins):
| Priority | Location | Description |
|---|---|---|
| 1 | ANSIBLE_CONFIG env var | Environment variable pointing to a config file |
| 2 | ./ansible.cfg | Current working directory |
| 3 | ~/.ansible.cfg | Home directory (hidden file) |
| 4 | /etc/ansible/ansible.cfg | System-wide default |
Tip: The most common approach is to place an
ansible.cfgfile in the root of your project directory alongside your playbooks and inventory.
[defaults]
inventory = ./inventory
remote_user = deploy
host_key_checking = False
retry_files_enabled = False
stdout_callback = yaml
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.