cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
683
Views
1
Helpful
1
Replies

Ansible Cisco IOS Save Changed Config

Netmart
Level 1
Level 1

Hello,

I wanted to save changes in running config by using the "save_when" parameter:

---

- name: Test Ansible ios_command on Cisco IOS XE

  hosts: iosxe

  vars_files:

         - /home/cisco/Ansible/vault_password2.yml

  vars:

      ansible_become_pass: "{{ vault_sudo_password }}"

      ansible_python_interpreter: /usr/bin/python3

   

  tasks:

     - name: Check the startup-config against the running-config

       cisco.ios.ios_config:

         diff_against: startup

   


     - name: Save running to startup when modified

       cisco.ios.ios_config:

         save_when: modified

*  changed

*  always

 

However, when using "changed"

task path: /home/cisco/Ansible/library/site-iosxe-CORE_Test-BGP-routeMap-prefixList-removal-vault_v2.yml:101

redirecting (type: connection) ansible.builtin.network_cli to ansible.netcommon.network_cli

redirecting (type: terminal) ansible.builtin.ios to cisco.ios.ios

redirecting (type: cliconf) ansible.builtin.ios to cisco.ios.ios

redirecting (type: action) cisco.ios.ios_config to cisco.ios.ios

redirecting (type: action) cisco.ios.ios_config to cisco.ios.ios

 

   save_when: modified

fatal: [10.0.0.1 ]: FAILED! => {"changed": false, "msg": "show running-config\r\nshowrunning-config\r\n     ^\r\n% Invalid input detected at '^' marker.\r\n\r\n;lab-c4500>"}

 

save_when: changed

Changed: ok: [10.0.0.1] => {"changed": false

 

save_when: always

 [10.0.0.1]: FAILED! => {"changed": false, "msg": "copy running-config startup-config\r\ncopy running-config startup-config\r\n  ^\r\n% Invalid input detected at '^' marker.\r\n\r\lab-c4500>\r\tlab-c4500>"}

 

I would appreciate any help.

 

Thanks,

1 Reply 1

Torbjørn
Spotlight
Spotlight

Since "changed" only triggers a configuration save when the current task has made a change, I believe you aren't allowed to run any higher privilege commands/you are stuck in user exec mode. You should verify that authentication and authorization works as intended. Can you run the playbook with the -vvv parameter and add the output here?

EDIT: The prompt in your error messages indicate that the session is indeed stuck in user exec mode. Verify the auth config and your ansible privilege escalation/"become" settings.

Happy to help! Please mark as helpful/solution if applicable.
Get in touch: https://torbjorn.dev