cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
878
Views
0
Helpful
0
Replies

Ansible always writes config even nothing changed

fhk-cwempe
Level 1
Level 1

Hello,

I am starting to use Ansible for our switch/router configuration.
I created a playbook with some tasks and at the end I want to 'write mem' the config if there have been changes.

 

    - name: Save config to NVRAM
      cisco.ios.ios_config:
        save_when: modified

 

But this gets executed every time.
Even if I delete all other tasks and do a manual 'write mem' right before.

The documentation says:

 

If the argument is set to modified, then the running-config will only be copied to the startup-config if it has changed since the last save to startup-config.

 

https://docs.ansible.com/ansible/latest/collections/cisco/ios/ios_config_module.html

Why is this nor working?
Am I missing something?

My test device:

 

Model              SW Version
-----              ----------
C9200CX-12P-2X2G   17.09.01  

 

Ansible output:

 

# ansible-playbook switch_config_devel3.yml --limit X-01-S1 -vvv
ansible-playbook [core 2.13.3]
  config file = /opt/MYCOMPANY/bsn-ansible-networking/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible-playbook
  python version = 3.9.13 (main, Nov 16 2022, 10:51:39) [GCC 8.5.0 20210514 (Red Hat 8.5.0-15)]
  jinja version = 3.1.2
  libyaml = True
Using /opt/MYCOMPANY/bsn-ansible-networking/ansible.cfg as config file
host_list declined parsing /opt/MYCOMPANY/bsn-ansible-networking/inventory/20_switches_routers.yml as it did not pass its verify_file() method
script declined parsing /opt/MYCOMPANY/bsn-ansible-networking/inventory/20_switches_routers.yml as it did not pass its verify_file() method
Skipping empty key (hosts) in group (A_02)
Parsed /opt/MYCOMPANY/bsn-ansible-networking/inventory/20_switches_routers.yml inventory source with yaml plugin
host_list declined parsing /opt/MYCOMPANY/bsn-ansible-networking/inventory/40_wireless_controller.yml as it did not pass its verify_file() method
script declined parsing /opt/MYCOMPANY/bsn-ansible-networking/inventory/40_wireless_controller.yml as it did not pass its verify_file() method
Parsed /opt/MYCOMPANY/bsn-ansible-networking/inventory/40_wireless_controller.yml inventory source with yaml plugin
host_list declined parsing /opt/MYCOMPANY/bsn-ansible-networking/inventory/90_global_vars.yml as it did not pass its verify_file() method
script declined parsing /opt/MYCOMPANY/bsn-ansible-networking/inventory/90_global_vars.yml as it did not pass its verify_file() method
Parsed /opt/MYCOMPANY/bsn-ansible-networking/inventory/90_global_vars.yml inventory source with yaml plugin
redirecting (type: action) cisco.ios.ios_config to cisco.ios.ios
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: switch_config_devel3.yml ******************************************************************************************************************************************************
1 plays in switch_config_devel3.yml

PLAY [all] ******************************************************************************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************************************************
task path: /opt/MYCOMPANY/bsn-ansible-networking/switch_config_devel3.yml:4
<192.168.2.200> ESTABLISH LOCAL CONNECTION FOR USER: root
<192.168.2.200> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-local-11824ttkugqmz `"&& mkdir "` echo /root/.ansible/tmp/ansible-local-11824ttkugqmz/ansible-tmp-1681476264.2298183-11828-114588160168504 `" && echo ansible-tmp-1681476264.2298183-11828-114588160168504="` echo /root/.ansible/tmp/ansible-local-11824ttkugqmz/ansible-tmp-1681476264.2298183-11828-114588160168504 `" ) && sleep 0'
Using module file /root/.ansible/collections/ansible_collections/cisco/ios/plugins/modules/ios_facts.py
<192.168.2.200> PUT /root/.ansible/tmp/ansible-local-11824ttkugqmz/tmpwf1rhed_ TO /root/.ansible/tmp/ansible-local-11824ttkugqmz/ansible-tmp-1681476264.2298183-11828-114588160168504/AnsiballZ_ios_facts.py
<192.168.2.200> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-local-11824ttkugqmz/ansible-tmp-1681476264.2298183-11828-114588160168504/ /root/.ansible/tmp/ansible-local-11824ttkugqmz/ansible-tmp-1681476264.2298183-11828-114588160168504/AnsiballZ_ios_facts.py && sleep 0'
<192.168.2.200> EXEC /bin/sh -c '/usr/bin/python3.9 /root/.ansible/tmp/ansible-local-11824ttkugqmz/ansible-tmp-1681476264.2298183-11828-114588160168504/AnsiballZ_ios_facts.py && sleep 0'
<192.168.2.200> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-local-11824ttkugqmz/ansible-tmp-1681476264.2298183-11828-114588160168504/ > /dev/null 2>&1 && sleep 0'
ok: [X-01-S1]
META: ran handlers
redirecting (type: action) cisco.ios.ios_config to cisco.ios.ios

TASK [Speichere Konfiguration, falls sie sich geändert hat] *****************************************************************************************************************************
task path: /opt/MYCOMPANY/bsn-ansible-networking/switch_config_devel3.yml:6
redirecting (type: action) cisco.ios.ios_config to cisco.ios.ios
redirecting (type: action) cisco.ios.ios_config to cisco.ios.ios
changed: [X-01-S1] => {
    "changed": true,
    "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": null,
            "match": "line",
            "multiline_delimiter": "@",
            "parents": null,
            "replace": "line",
            "running_config": null,
            "save_when": "modified",
            "src": null
        }
    }
}
META: ran handlers
META: ran handlers

PLAY RECAP ******************************************************************************************************************************************************************************
X-01-S1                    : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

 

 

0 Replies 0