10-29-2023 10:56 PM
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,
10-29-2023 11:50 PM - edited 10-29-2023 11:53 PM
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.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide