Inventory is the design document
YAML
all:
children:
campus:
children:
access:
hosts:
sw-a-01: { ansible_host: 10.10.10.21 }
sw-a-02: { ansible_host: 10.10.10.22 }
distribution:
hosts:
dsw-01: { ansible_host: 10.10.10.11 }
vars:
ansible_network_os: cisco.ios.ios
ansible_connection: ansible.netcommon.network_cliPrefer resource modules over raw commands
YAML
- name: Ensure access VLANs exist
cisco.ios.ios_vlans:
config:
- vlan_id: 110
name: SITE1-USER
- vlan_id: 120
name: SITE1-VOICE
state: merged
- name: Ensure NTP servers
cisco.ios.ios_ntp_global:
config:
servers:
- server: 10.10.10.53
- server: 10.10.10.54
state: replacedDiff before you change
Bash
ansible-playbook site.yml --limit access --check --diff
ansible-playbook site.yml --limit sw-a-01 --diffRollout pattern
Apply to one canary device and validate with an assertion playbook.
Roll out per closet with serial: 1 and a health gate between batches.
Save the configuration only after validation passes.
YAML
- name: Validate reachability after change
ansible.builtin.assert:
that:
- "'up' in interface_state.stdout[0]"
fail_msg: "Uplink down after change — halting rollout"Guardrails
Never store enable secrets in the inventory; use a vault or an external secret store.
Keep a scheduled config backup job independent of the change playbooks.
Make every playbook safe to run twice.