# Cisco IOS collection unable to display config diff

**URL:** <https://forum.ansible.com/t/cisco-ios-collection-unable-to-display-config-diff/7256>\
**Category:** Get Help\
**Tags:** cisco, playbook, collections\
**Created:** [July 12, 2024, 7:57pm UTC](https://forum.ansible.com/t/cisco-ios-collection-unable-to-display-config-diff/7256 "2024-07-12T19:57:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jonathan/32/4215_2.png) [@Jonathan](https://forum.ansible.com/u/Jonathan)\
**Post date:** [July 12, 2024, 7:57pm UTC](https://forum.ansible.com/t/cisco-ios-collection-unable-to-display-config-diff/7256/1 "2024-07-12T19:57:17Z")

</div>

Hello all, I’m new to using Ansible, and this forum so please let me know if I’m doing something wrong here. The results below are from a lab I have set up to develop my companies Ansible capabilities.

**The goal:**  
To use the base-config.cfg file (expressed as the variable master\_config) to use as a reference point to ensure the lab switches are running the exact same config.

This has been accomplished! This totally works and it’s repeatable (thank you chatgpt).

**Where I’m struggling:**  
The only time I can consistently JUST see the diff is by using the --diff module when running the playbook. You’ll see below that caching the diff in **register: config\_diff** and attempting to display it using **debug: var: config\_diff** does not work.

The code itself is here at the top, while the output/ logs are at the bottom of this post.

The code

```auto
**- name: Standard SW Provisioning playbook**

**hosts: switches**

**gather_facts: no**

**tasks:**

**- name: Pre-load master config**
 **set_fact:**
**master_config: "{{ lookup('file', 'master.cfg/base-config.cfg') }}"**

**- name: Check running-config against master config**
 **cisco.ios.ios_config:**
 **diff_against: intended**
 **intended_config: "{{ master_config }}"**
 **match: line**
 **register: config_diff** 

**- name: Display the configuration differences**
 **debug:**
 **var: config_diff**

**- name: Apply master config when differences are found**
 **cisco.ios.ios_config:**
 **lines: "{{ master_config }}"**
 **when: config_diff is defined and config_diff != ''**

```

LOGS/ OUTPUT BELOW

This is the result from the **var: config\_diff** line:  
**ok: [10.10.41.2] =\> {**  
\*\* “config\_diff”: {\*\*  
\*\* “changed”: false,\*\*  
\*\* “failed”: false\*\*  
\*\* }\*\*  
**}**  
**ok: [10.10.41.3] =\> {**  
\*\* “config\_diff”: {\*\*  
\*\* “changed”: false,\*\*  
\*\* “failed”: false\*\*  
\*\* }\*\*  
**}**

However, when the **cisco.ios.ios\_config collection** runs, it detects the changes I’m making to the switches and accordingly changes the running config to match the **base-config.cfg**

**changed: [redacted] =\> {**  
\*\* “banners”: {},\*\*  
\*\* “changed”: true,\*\*  
\*\* “commands”: [\*\*  
\*\* “hostname labcat1”\*\*  
\*\* ],\*\*  
\*\* “invocation”: {\*\*  
\*\* “module\_args”: {\*\*  
\*\* “after”: null,\*\*  
\*\* “backup”: false,\*\*  
\*\* “backup\_options”: null,\*\*  
\*\* “before”: null,\*\*  
\*\* “defaults”: false,\*\*  
\*\* “diff\_against”: null,\*\*  
\*\* “diff\_ignore\_lines”: null,\*\*  
\*\* “intended\_config”: null,\*\*  
\*\* “lines”: [\*\*  
\*\* “hostname labcat1\ninterface GigabitEthernet1/0/1\n description hey over here\n!\ninterface Vlan10\n ip address 192.168.1.1 255.255.255.0\n!”\*\*  
\*\* ],\*\*  
\*\* “match”: “line”,\*\*  
\*\* “multiline\_delimiter”: “@”,\*\*  
\*\* “parents”: null,\*\*  
\*\* “replace”: “line”,\*\*  
\*\* “running\_config”: null,\*\*  
\*\* “save\_when”: “never”,\*\*  
\*\* “src”: null\*\*  
\*\* }\*\*  
\*\* },\*\*  
\*\* “updates”: [\*\*  
\*\* “hostname labcat1”\*\*  
\*\* ]\*\*  
**}**  
**changed: [redacted] =\> {**  
\*\* “banners”: {},\*\*  
\*\* “changed”: true,\*\*  
\*\* “commands”: [\*\*  
\*\* “hostname labcat1”\*\*  
\*\* ],\*\*  
\*\* “invocation”: {\*\*  
\*\* “module\_args”: {\*\*  
\*\* “after”: null,\*\*  
\*\* “backup”: false,\*\*  
\*\* “backup\_options”: null,\*\*  
\*\* “before”: null,\*\*  
\*\* “defaults”: false,\*\*  
\*\* “diff\_against”: null,\*\*  
\*\* “diff\_ignore\_lines”: null,\*\*  
\*\* “intended\_config”: null,\*\*  
\*\* “lines”: [\*\*  
\*\* “hostname labcat1\ninterface GigabitEthernet1/0/1\n description hey over here\n!\ninterface Vlan10\n ip address 192.168.1.1 255.255.255.0\n!”\*\*  
\*\* ],\*\*  
\*\* “match”: “line”,\*\*  
\*\* “multiline\_delimiter”: “@”,\*\*  
\*\* “parents”: null,\*\*  
\*\* “replace”: “line”,\*\*  
\*\* “running\_config”: null,\*\*  
\*\* “save\_when”: “never”,\*\*  
\*\* “src”: null\*\*  
\*\* }\*\*  
\*\* },\*\*  
\*\* “updates”: [\*\*  
\*\* “hostname labcat1”\*\*  
\*\* ]\*\*  
**}**

---

<div class="post-metadata">

**Author:** ![mikemorency](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mikemorency/32/2672_2.png) [@mikemorency](https://forum.ansible.com/u/mikemorency)\
**Post date:** [July 18, 2024, 3:36pm UTC](https://forum.ansible.com/t/cisco-ios-collection-unable-to-display-config-diff/7256/2 "2024-07-18T15:36:18Z")

</div>

Hi!

So first, based on the module [docs](https://docs.ansible.com/ansible/latest/collections/cisco/ios/ios_config_module.html) the `diff_against` attribute only matters when the `--diff` flag is applied. So it sounds like what your seeing is expected. If you run that task without the `--diff` flag, it seems like it does nothing

Second, your `when` clause not quite doing what you want

1. `config_diff` will always be defined at this point since the task where `config_diff` is registered always runs (theres no `when` clause or tags on the task that might cause it to be skipped)
2. `config_diff` is a dictionary, and will never be equal to an empty string.

Im not sure what a good `when` clause looks like for this module since im not familiar with the output. But maybe something like

```auto
when: config_diff.commands is defined and (config_diff.commands | length) > 0

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [August 17, 2024, 3:36pm UTC](https://forum.ansible.com/t/cisco-ios-collection-unable-to-display-config-diff/7256/3 "2024-08-17T15:36:33Z")

</div>

Closed on August 17, 2024, 3:36pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
