Stage 4 · Provision
Ansible Fundamentals
Install & First Inventory
Control node setup, INI vs YAML inventory, and connection basics.
Control Node Setup
Ansible runs on a control node — any machine with Python 3.9+ and SSH access to your managed nodes. This can be your laptop, a bastion host, or a CI server. Managed nodes need only Python and SSH; no Ansible installation required.
# macOS
brew install ansible
# Ubuntu/Debian
sudo apt update && sudo apt install -y ansible
# RHEL/CentOS/Fedora
sudo dnf install -y ansible-core
# Verify installation
ansible --versionThe package name changed from ansible to ansible-core in recent versions. Both provide the ansible command.
INI Inventory Format
An inventory file defines the hosts and groups Ansible will manage. The simplest format is INI — hostnames listed under group headers in square brackets.
[webservers]
web1.example.com
web2.example.com
web3.example.com
[dbservers]
db1.example.com
db2.example.com
[production:children]
webservers
dbserversGroup inheritance uses the :children suffix. The production group contains all hosts from both webservers and dbservers.
YAML Inventory Format
YAML inventory is more expressive — it supports host variables, group variables, and nested hierarchies in a structured format.
all:
children:
webservers:
hosts:
web1.example.com:
http_port: 80
web2.example.com:
http_port: 443
vars:
ansible_user: deploy
dbservers:
hosts:
db1.example.com:
db2.example.com:YAML inventory lets you define per-host variables directly in the inventory file. For larger fleets, use group_vars and host_vars directories instead.
ansible.cfg Essentials
ansible.cfg controls Ansible's behavior. Place it in your project directory for per-project settings, or in ~/.ansible.cfg for global defaults.
[defaults]
inventory = ./inventory.yml
remote_user = deploy
host_key_checking = False
retry_files_enabled = False
[privilege_escalation]
become = True
become_method = sudo
become_user = rootdisabling host_key_checking speeds up development. Never disable it in production without understanding the security implications.
Ansible searches for config files in order: ANSIBLE_CONFIG env var, ./ansible.cfg, ~/.ansible.cfg, /etc/ansible/ansible.cfg. The first found wins. Be explicit about which config file you use.
Testing Your First Connection
Use ansible ping (the module, not the system command) to verify connectivity. This tests SSH, authentication, and Python availability on managed nodes.
# Ping all hosts in inventory
ansible all -m ping
# Ping a specific group
ansible webservers -m ping
# Run with verbose output
ansible all -m ping -v
# Use a different inventory file
ansible all -m ping -i inventory.ymlA successful ping means Ansible can SSH in, transfer a module, and execute it. If it fails, check SSH access, credentials, and Python availability.
Run ansible all -m setup to see all facts Ansible collects about each host. This confirms your inventory is correct and tells you what facts are available for conditionals.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.