Skip to content
Dorian FINKEL
AnsibleCisco IOSGitLessons learned · 2025 · 3 min read · Updated 9 October 2026

Ansible on Cisco: review before you apply

Configuring switches by hand creates drift and erases history. An inventory by role, Jinja2 templates, a systematic check/diff pass, small rollout batches, and every configuration ends up versioned in Git.

01The cost of doing it by hand

Each switch configured separately ends up differing from the others, and nobody knows any more which change was made, when, or why. The problem isn’t speed: it’s consistency and traceability.

02Inventory and templates

The inventory groups devices by site and by role (access, distribution, core). Jinja2 templates describe what a role must have (VLANs, interfaces, NTP, syslog, AAA) once, for all; site-specific values live in group variables.

Example · templates/access.j2
{% for vlan in vlans %}
vlan {{ vlan.id }}
 name {{ vlan.name }}
{% endfor %}
ntp server {{ ntp_server }}
logging host {{ syslog_server }}

03The playbook

ios_config compares the template lines with the running configuration and only sends the missing ones. save_when: modified writes the startup configuration only if something changed; serial limits each pass to a few devices, so a mistake doesn’t hit the whole fleet at once.

Example · site.yml
- name: Access switch configuration
  hosts: access
  gather_facts: false
  serial: 5
  tasks:
    - name: Apply the role template
      cisco.ios.ios_config:
        src: templates/access.j2
        save_when: modified

04Always review the diff

Before any change, the playbook runs in check and diff mode: Ansible shows the lines it would send, without modifying anything. You review, then apply to the intended scope.

Check mode is only reliable if every module supports it: ios_config does, a shell task or a third-party module may not.

Example · Shell
# Dry run: what would change, touching nothing
ansible-playbook site.yml --limit paris --check --diff

# Apply, once the diff has been reviewed
ansible-playbook site.yml --limit paris

05Going further: resource modules

ios_config reasons in lines of text. Resource modules (cisco.ios.ios_vlans, ios_interfaces…) describe the desired state as structured data, with a “merged” state that adds and a “replaced” or “overridden” state that also removes what isn’t declared. They are idempotent by design, and easier to review.

06History in Git

A daily backup of the configurations goes into a Git repository: every change has its date and diff, and rolling back becomes a simple operation.

07Lab first

Everything was validated on Cisco IOS switches emulated in EVE-NG before touching real equipment.

Key takeaways

  • One template per role, written once; values in variables.
  • check + diff before every change.
  • serial: roll out in small batches; save_when: modified to save.
  • Configurations backed up and versioned daily.
  • Validate in the lab before production.

Official sources