Ansible: Automate Everything from First Playbook to Production · Foundations: Installation, Inventory and Ad-hoc Commands

Install Ansible and Configure Your Control Node

Install Ansible via pip, verify the version, understand the control-node / managed-node split, and create an ansible.cfg that points at your inventory.

Members can save this page, take notes and track progress. See membership · Sign in

What you'll build

A working Ansible control node: Ansible installed, version verified, and a minimal ansible.cfg that sets the inventory path and disables host-key checking for lab use.

The idea

Ansible follows a push-based, agentless model. You run commands from a single machine called the control node; it connects to managed nodes over SSH (Linux) or WinRM (Windows) and executes tasks there. Managed nodes need nothing installed except Python 3 — no agent, no daemon, no open port beyond SSH.

The control node needs:

  1. Python 3.10+ (the ansible package is pure Python).
  2. SSH client (ssh) for connecting to managed nodes.
  3. ansible.cfg in the project root (or ~/.ansible.cfg) to set defaults.

The recommended install method is pip install ansible inside a virtual environment. Distribution packages (apt install ansible) work but are often several versions behind.

ansible.cfg cascades: Ansible checks ANSIBLE_CONFIG env var → ./ansible.cfg (project root) → ~/.ansible.cfg → /etc/ansible/ansible.cfg. A per-project ansible.cfg keeps settings portable and versioned.

The code

Install Ansible and check version
pip install --quiet ansible
ansible --version | head -6

Output

Run this on your computer — see “Get Started” for setup.

Create a minimal project with an ansible.cfg and a local inventory:

Create a project with ansible.cfg
mkdir -p ansible-lab && cd ansible-lab

cat > ansible.cfg << 'EOF'
[defaults]
inventory = inventory.ini
host_key_checking = False
retry_files_enabled = False
stdout_callback = yaml

[ssh_connection]
pipelining = True
EOF

cat > inventory.ini << 'EOF'
[local]
localhost ansible_connection=local
EOF

ansible --version | grep "config file"
ansible all --list-hosts

Output

Run this on your computer — see “Get Started” for setup.

Key settings in ansible.cfg:

Setting Purpose
inventory Default inventory file path
host_key_checking = False Skip SSH fingerprint prompts (labs only — enable in production)
retry_files_enabled = False Don't create .retry files after failures
stdout_callback = yaml Human-readable task output instead of JSON
pipelining = True Reduce SSH round trips by running multiple commands per connection

Common mistakes

  • Installing with sudo pip install. This pollutes the system Python. Use a virtual environment or pipx install ansible.
  • Leaving host_key_checking = False in production. An attacker who intercepts SSH connections can inject commands. Use ssh-keyscan to populate known_hosts before the first run.
  • Forgetting Python on managed nodes. Ansible modules execute Python on the remote host. If a minimal server image has no Python, the raw module or ansible.builtin.package with gather_facts: false can bootstrap it.
  • Using an outdated distribution package. apt install ansible on Ubuntu 22.04 installs Ansible 2.10; the current version is 2.17+. Features like ansible.builtin FQCNs and improved error messages require recent versions.

Key points

  • Ansible is agentless: control node pushes over SSH, managed nodes need only Python 3.
  • Install with pip install ansible in a virtualenv for the latest version.
  • ansible.cfg in the project root sets defaults; it cascades from env var → project → home → system.
  • Disable host_key_checking only in lab environments.
  • pipelining = True measurably speeds up playbook runs.

Further reading: Installing Ansible · Ansible configuration

Practice questions

What does the control node need that managed nodes do not?

Answer

The control node needs Ansible installed (the Python package). Managed nodes only need Python 3 and an SSH server — no Ansible package, no agent, no daemon.

Why is pipelining = True recommended?

Answer

With pipelining enabled, Ansible sends the module code and executes it in one SSH session instead of copying a temporary file first. This reduces SSH round trips and speeds up playbook runs, especially on high-latency connections.

In what order does Ansible look for ansible.cfg?

Answer

ANSIBLE_CONFIG environment variable → ./ansible.cfg (current directory) → ~/.ansible.cfg (home directory) → /etc/ansible/ansible.cfg (system). The first one found wins.

Open in the app to mark lessons complete, take notes and track your progress.

Last reviewed · By the ByteCamel team · How we write content

Was this page helpful?

Report a mistake