← Interview Prep

Ansible — Theory

Ansible for network automation: agentless/idempotent architecture, inventory, playbooks/roles/handlers, variables & precedence, Jinja2 templates, network connection plugins (network_cli/netconf/httpapi), resource modules, and Vault.

Ansible is the default answer to "how do you push config to a fleet without writing bespoke scripts." It's agentless (SSH / network API, nothing to install on the device), declarative (YAML describing desired state), and idempotent (re-running converges, it doesn't re-do). For network automation it drives CLI, NETCONF, and HTTP-API devices the same way.

The one-liner: Ansible reads an inventory, runs tasks (each calling a module) from a playbook against those hosts, over a connection plugin — and reports changed vs ok so re-runs are safe.

Architecture

PieceRole
Control nodeWhere Ansible runs (needs Python). No controller agent on targets.
Managed nodesServers (SSH + Python) or network devices (CLI/NETCONF/API — no Python needed).
InventoryThe hosts and groups, plus their variables. Static (INI/YAML) or dynamic (a script/plugin).
ModulesThe unit of work (ios_config, ansible.builtin.copy, uri). Idempotent; report changed/ok/failed.
PluginsConnection (network_cli, netconf, httpapi, ssh), filter, lookup, callback, inventory.
CollectionsPackaged modules/roles/plugins from Galaxy (cisco.ios, arista.eos, community.general).

Core building blocks

Network automation specifics

Network devices differ from servers: usually no Python on-box, so you pick a network connection plugin and set ansible_network_os.

ConnectionUse
network_cliSSH into the CLI (ios_*, eos_*, nxos_*, cli_command).
netconfNETCONF/YANG (netconf_config, junipernetworks.junos).
httpapiREST/eAPI (Arista eAPI, Cisco NX-API, F5).

Variable precedence (the classic question)

When the same variable is defined in several places, the most specific / latest wins. Simplified low→high:

PrioritySource
lowestrole defaults/
inventory group_vars/all → specific group → host_vars
play vars → role vars (vars/) → block/task vars
highestset_fact / registered vars, then -e extra-vars (always win)

Rule of thumb: defaults/ is the weakest (meant to be overridden), extra-vars (-e) always win, and host_vars beat group_vars. More drills in Python Automation.

Running it

# ad-hoc: one module, no playbook
ansible ios --connection network_cli -m cisco.ios.ios_command -a "commands='show version'"

# playbook, dry-run first, then for real
ansible-playbook site.yml -i inventory.yml --check --diff
ansible-playbook site.yml -i inventory.yml --limit edge --tags vlans

ansible-vault encrypt group_vars/all/secrets.yml    # protect secrets

Likely interview questions

Related: Ansible — Cases & Usage · Ansible Lab (Python) · Python Automation.