Hi guys, i 've been tasked for deletion of "ip sla x" lines at several
routers.
I have created this playbook, that works fine with all routers, except the
ones which do not have "ip sla x" configured.
This is the playbook:
---
- name: IOS show command
hosts: test
connection: local
gather_facts: no
vars:
cli:
username: cisco
password: cisco
tasks:
- ios_command:
commands:
- show run | i ip sla [0-9]
provider: "{{ cli }}"
register: showcommand
- debug: msg="{{ showcommand.stdout_lines }}"
- ios_config:
lines: no {{item}}
provider: "{{ cli }}"
with_items: "{{showcommand.stdout_lines}}"
when: showcommand.stdout != ""
register: configcommand
Example, if router has an output for "sh run | inc ip sla" and show "*ip
sla 1*".
ok: [test1] => {
"msg": [
[
"ip sla 1",
]
]
then the ios_config will execute "no ip sla 1", and it works perfectly.
Even when several ip sla numbers are there from multiple ip sla tracks
configurations.
But if the router does not have and ip sla configured, then the output will
be an empty but defined
ok: [test1] => {
"msg": [
[
""
]
]
And this will cause an execution of a command as "no ", and that creates an
error, because the command is incomplete.
I have been browsing on this, and tested the "when x != "" " statement for "
with_items", it works fine to control the loop when the router has an "ip
sla x" to remove, but it seems to enter the loop anyway when the output is ""
(an empty string), for cases where routers do not have ip sla configured.
I don't know if this is an issue, something that i'm doing wrong, even
wrong way to solve this requirement.
What do you think?
if you reach here at reading this email.... *thanks for you time ;)*
regards
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/4bf8d369-3e97-4a11-a190-f1e92cd72f3f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.