Install Ansible & How the Sessions Run
Ansible is installed only on the control node. Managed nodes need nothing but an SSH server and Python 3, which every mainstream Linux distribution already has.
Two packages: ansible-core and ansible
| Package | Contents | Version in this course |
|---|---|---|
ansible-core |
the engine, the CLI tools and the ansible.builtin collection (about 70 modules: copy, file, template, command, apt, dnf, service, user, …) |
2.21.5 |
ansible |
ansible-core plus a curated bundle of community collections (community.general, ansible.posix, amazon.aws, kubernetes.core, …) |
14.5.0 |
Install ansible when you want everything; install ansible-core plus only the collections you need (see Galaxy) when you want a small, pinned toolchain, which is what CI pipelines usually do.
Installing
Ansible is a Python application. Install it into its own environment, never into the system Python:
# pipx or uv keep it isolated from other Python tools
pipx install --include-deps ansible
uv tool install ansible-core --with ansible # what this course's sandbox uses
uv tool install ansible-lint --with ansible-core # the linter, see the ansible-lint lesson
# or a plain virtual environment pinned in requirements.txt (common in CI)
python3 -m venv .venv && . .venv/bin/activate
pip install "ansible-core==2.21.5" "ansible==14.5.0"
# distribution packages exist too, but are often a few versions behind
sudo apt install ansible # Ubuntu/Debian
sudo dnf install ansible-core # Fedora/RHELWindows is not supported as a control node; use WSL. Managed nodes can be Windows (over WinRM or SSH, with the ansible.windows collection) or network devices (with their own connection plugins).
Check what you installed:
ansible --version
ansible-lint --version
molecule --version | head -1ansible [core 2.21.5]
config file = None
configured module search path = ['/home/learner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /opt/uv-tools/ansible-core/lib/python3.13/site-packages/ansible
ansible collection location = /home/learner/.ansible/collections:/usr/share/ansible/collections
executable location = /opt/uv-tools/ansible-core/bin/ansible
python version = 3.13.18 (main, Oct 26 2026, 14:08:20) [Clang 23.1.3 ] (/opt/uv-tools/ansible-core/bin/python)
jinja version = 3.1.6
pyyaml version = 6.0.3 (with libyaml v0.2.5)
ansible-lint 26.10.1 using ansible-core:2.21.5 ansible-compat:26.10.0 ruamel-yaml:0.19.1
molecule 26.10.0 using python 3.13
The --version output is worth reading once. It tells you which config file is in effect (none yet), where Ansible looks for modules and collections, and which Python runs Ansible itself.
How the sessions in this course work
Every bash run block is a real session, verified in a fresh container with no network, no root and no SSH server:
- Playbooks target
localhost, either the implicitlocalhost(no inventory needed) or inventory hosts withansible_connection=local. The modules really run and really change files under/home/learner. - Tasks that need root or a real server (
become,apt/dnf,service,user, SSH to other hosts) are shown as sample sessions: plainbashblocks with realistic output, next to a verified local equivalent. The become lesson explains this. - Colour is off, and plays use
gather_facts: falseunless the lesson is about facts, so the output is the same on every run. ansible-lint,ansible-doc,ansible-inventory,ansible-vaultand Molecule (with its delegated driver) all run for real. Installing from Galaxy needs the network, so it is a sample session; the collection bundle is already installed.
The implicit localhost
When a play says hosts: localhost and your inventory doesn't define localhost, Ansible creates an implicit localhost: connection local, Python = the one running Ansible. That is the quickest way to try a module:
cat > ping.yml <<'YML'
- name: Ping the control node itself
hosts: localhost
gather_facts: false
tasks:
- name: Ping
ansible.builtin.ping:
YML
ansible-playbook ping.yml
PLAY [Ping the control node itself] ********************************************
TASK [Ping] ********************************************************************
ok: [localhost]
PLAY RECAP *********************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Local hosts in an inventory, and the interpreter warning
Once hosts come from an inventory, Ansible discovers which Python to use on each host and warns about it, because a later Python upgrade on the server could change the choice:
printf '[web]\nweb1 ansible_connection=local\n' > inventory.ini
ansible -i inventory.ini web -m ansible.builtin.ping[WARNING]: Host 'web1' is using the discovered Python interpreter at '/opt/uv-tools/ansible-core/bin/python3.13', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.21/reference_appendices/interpreter_discovery.html for more information.
web1 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/opt/uv-tools/ansible-core/bin/python3.13"
},
"changed": false,
"ping": "pong"
}
On real servers you either pin the interpreter per group (ansible_python_interpreter=/usr/bin/python3) or keep discovery but silence it with interpreter_python = auto_silent in ansible.cfg. The sessions in this course do the second:
cat > ansible.cfg <<'INI'
[defaults]
inventory = inventory.ini
interpreter_python = auto_silent
INI
printf '[web]\nweb1 ansible_connection=local\n' > inventory.ini
ansible web -m ansible.builtin.pingweb1 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/opt/uv-tools/ansible-core/bin/python3.13"
},
"changed": false,
"ping": "pong"
}
The warning is gone. (Older tutorials add -o for one line per host; ansible-core 2.21 deprecates both the flag and the oneline callback behind it, and 2.23 removes them.) With inventory = in ansible.cfg you no longer need -i. The configuration lesson explains where Ansible looks for ansible.cfg and why the file in the current folder wins.
A practice lab of your own
To try the sample sessions (SSH, become, packages, services) for real, give yourself two or three throwaway Linux VMs:
| Option | Command |
|---|---|
| Multipass (Ubuntu VMs) | multipass launch 24.04 --name web1 --cloud-init keys.yaml |
| Vagrant + VirtualBox/libvirt | a Vagrantfile with config.vm.define "web1" blocks |
| Containers with systemd | Docker or Podman containers running an SSH server; quick, but services behave differently than on a VM |
| Cloud VMs | create them with Terraform, as in Create with Terraform, Configure with Ansible; destroy them afterwards |
Put your public SSH key on each VM (see SSH Keys & ssh-agent), list them in an inventory, and ansible all -m ping should answer pong from each.
Test yourself
Where must Ansible be installed?
- On every managed server
- Only on the control node
- On a central Ansible server that agents poll
- On the DNS server
What is the difference between ansible-core and ansible?
ansibleis the old nameansibleisansible-coreplus a bundle of community collectionsansible-corehas no CLIansible-coreruns only on Windows
What does interpreter_python = auto_silent do?
- Disables Python on the host
- Keeps interpreter discovery but hides the warning about it
- Uses Python 2
- Makes all tasks silent