On 20.03.2018 02:29, [email protected] wrote:
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": [
[
""
]
]
You should ha provided the content of the variable showcommand
- debug: var=showcommand
Since I don't use ios_command and don't have the content this might be
completely wrong.
I thing you need to use showcommand.stdout and not
showcommand.stdout_lines.
When using that with with_items you will have the content of each of
them in the variable item so you need to use item in when:
with_items: "{{ showcommand.stdout }}"
when: item != ""
--
Kai Stian Olstad
--
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/0da34584ede396c8f6e8ba14c625421c%40olstad.com.
For more options, visit https://groups.google.com/d/optout.