<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Ansible WHen statement based an previous Output in Code Exchange</title>
    <link>https://community.cisco.com/t5/code-exchange/ansible-when-statement-based-an-previous-output/m-p/4962648#M38</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I wanted to create a condition to execute only an ios command when it is part of previous output of "sh run | sec eigrp".&lt;/P&gt;&lt;P&gt;It works to remove the eigrp process, but it skippes the removal of route-map, though it is part of output.&lt;/P&gt;&lt;P&gt;Please see output below and let me know any suggestions.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Playbook:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;---&lt;BR /&gt;- name: Ansible ios_command on Cisco IOS XE&lt;BR /&gt;hosts: iosxe&lt;BR /&gt;vars_files:&lt;BR /&gt;- /home/cisco/Ansible/vault_password2.yml&lt;BR /&gt;vars:&lt;BR /&gt;ansible_become_pass: "{{ vault_sudo_password }}"&lt;BR /&gt;ansible_python_interpreter: /usr/bin/python3&lt;/P&gt;&lt;P&gt;tasks:&lt;BR /&gt;&lt;BR /&gt;- name: show ip route and bfd neighbors prior to changes&lt;BR /&gt;ios_command:&lt;BR /&gt;commands:&lt;BR /&gt;- sh run | sec eigrp&lt;/P&gt;&lt;P&gt;become: true&lt;BR /&gt;register: output1&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;- name: "BGP: no EIGRP redist route map"&lt;BR /&gt;ios_config:&lt;BR /&gt;lines:&lt;BR /&gt;- no redistribute eigrp 10 route-map EIGRP-2-BGP&lt;BR /&gt;parents:&lt;BR /&gt;- router bgp 65411&lt;BR /&gt;- address-family ipv4&lt;BR /&gt;when: output1.stdout is search("redistribute eigrp 10 route-map EIGRP-2-BGP")&lt;BR /&gt;&lt;BR /&gt;become: true&lt;BR /&gt;register: output2&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;- name: "no router eigrp 10"&lt;BR /&gt;ios_config:&lt;BR /&gt;commands:&lt;BR /&gt;- no router eigrp 10&lt;BR /&gt;when: output1.stdout is search("router eigrp 10")&lt;BR /&gt;&lt;BR /&gt;become: true&lt;BR /&gt;register: output3&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;- name: show ip route and bfd neighbors after changes&lt;BR /&gt;ios_command:&lt;BR /&gt;commands:&lt;BR /&gt;- sh ip route vrf mgmtVrf&lt;BR /&gt;- sh ip bgp summary&lt;BR /&gt;- sh ip route&lt;BR /&gt;- sh bfd neighbors&lt;/P&gt;&lt;P&gt;become: true&lt;BR /&gt;register: output4&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;- name: print result1-show run | sec eigrp&lt;BR /&gt;debug:&lt;BR /&gt;var: output1&lt;/P&gt;&lt;P&gt;- name: print result2-BGP no EIGRP redist route map&lt;BR /&gt;debug:&lt;BR /&gt;var: output2&lt;BR /&gt;&lt;BR /&gt;- name: print result3-no router eigrp 10&lt;BR /&gt;debug:&lt;BR /&gt;var: output3&lt;BR /&gt;&lt;BR /&gt;- name: print result4-show ip route and bfd neighbors after changes&lt;BR /&gt;debug:&lt;BR /&gt;var: output4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Reduced output&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;~/Ansible$ ansible-playbook -i inventories/hosts-lab library/site-eos-eigrp-remove-when.yml -u cisco -k --ask-vault-pass&lt;BR /&gt;SSH password:&lt;BR /&gt;Vault password:&lt;/P&gt;&lt;P&gt;PLAY [Ansible ios_command on Cisco IOS XE] **********************************************************************************************************************************************************************************&lt;/P&gt;&lt;P&gt;TASK [Gathering Facts] **********************************************************************************************************************************************************************************************************************&lt;BR /&gt;ok: [10.0.0.1]&lt;/P&gt;&lt;P&gt;TASK [show ip route and bfd neighbors prior to changes] *************************************************************************************************************************************************************************************&lt;BR /&gt;ok: [10.0.0.1]&lt;/P&gt;&lt;P&gt;TASK [BGP: no EIGRP redist route map] *******************************************************************************************************************************************************************************************************&lt;BR /&gt;skipping: [10.0.0.1]&lt;/P&gt;&lt;P&gt;TASK [no router eigrp 10] *******************************************************************************************************************************************************************************************************************&lt;BR /&gt;[WARNING]: To ensure idempotency and correct diff the input configuration lines should be similar to how they appear if present in the running configuration on device&lt;BR /&gt;changed: [10.0.0.1]&lt;/P&gt;&lt;P&gt;TASK [show ip route and bfd neighbors after changes] ****************************************************************************************************************************************************************************************&lt;BR /&gt;ok: [10.0.0.1]&lt;/P&gt;&lt;P&gt;TASK [print result1-show run | sec eigrp] ***************************************************************************************************************************************************************************************************&lt;BR /&gt;ok: [10.0.0.1] =&amp;gt; {&lt;BR /&gt;"output1": {&lt;BR /&gt;"changed": false,&lt;BR /&gt;"failed": false,&lt;BR /&gt;"stdout": [&lt;BR /&gt;"router eigrp 10\n distribute-list route-map RM-EIGRP-DL-IN in \n shutdown\n redistribute eigrp 10 route-map RM-EIGRP-2-BGP"&lt;BR /&gt;],&lt;BR /&gt;"stdout_lines": [&lt;BR /&gt;[&lt;BR /&gt;"router eigrp 10",&lt;BR /&gt;" distribute-list route-map RM-EIGRP-DL-IN in ",&lt;BR /&gt;" shutdown",&lt;BR /&gt;" &lt;STRONG&gt;redistribute eigrp 10 route-map RM-EIGRP-2-BGP&lt;/STRONG&gt;"&lt;BR /&gt;]&lt;BR /&gt;]&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;TASK [print result2-BGP no EIGRP redist route map] ******************************************************************************************************************************************************************************************&lt;BR /&gt;ok: [10.0.0.1] =&amp;gt; {&lt;BR /&gt;"output2": {&lt;BR /&gt;"changed": false,&lt;BR /&gt;"false_condition": "output1.stdout is search(\"&lt;STRONG&gt;redistribute eigrp 10 route-map EIGRP-2-BGP&lt;/STRONG&gt;\")",&lt;BR /&gt;"skip_reason": "Conditional result was False",&lt;BR /&gt;"skipped": true&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;TASK [print result3-no router eigrp 10] *****************************************************************************************************************************************************************************************************&lt;BR /&gt;ok: [10.0.0.1] =&amp;gt; {&lt;BR /&gt;"output3": {&lt;BR /&gt;"banners": {},&lt;BR /&gt;"changed": true,&lt;BR /&gt;"commands": [&lt;BR /&gt;"no router eigrp 10"&lt;BR /&gt;],&lt;BR /&gt;"failed": false,&lt;BR /&gt;"updates": [&lt;BR /&gt;"no router eigrp 10"&lt;BR /&gt;],&lt;BR /&gt;"warnings": [&lt;BR /&gt;"To ensure idempotency and correct diff the input configuration lines should be similar to how they appear if present in the running configuration on device"&lt;BR /&gt;]&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;:&lt;/P&gt;&lt;P&gt;PLAY RECAP **********************************************************************************************************************************************************************************************************************************&lt;BR /&gt;10.0.0.1 : ok=8 changed=1 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 20 Nov 2023 04:45:03 GMT</pubDate>
    <dc:creator>Netmart</dc:creator>
    <dc:date>2023-11-20T04:45:03Z</dc:date>
    <item>
      <title>Ansible WHen statement based an previous Output</title>
      <link>https://community.cisco.com/t5/code-exchange/ansible-when-statement-based-an-previous-output/m-p/4962648#M38</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I wanted to create a condition to execute only an ios command when it is part of previous output of "sh run | sec eigrp".&lt;/P&gt;&lt;P&gt;It works to remove the eigrp process, but it skippes the removal of route-map, though it is part of output.&lt;/P&gt;&lt;P&gt;Please see output below and let me know any suggestions.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Playbook:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;---&lt;BR /&gt;- name: Ansible ios_command on Cisco IOS XE&lt;BR /&gt;hosts: iosxe&lt;BR /&gt;vars_files:&lt;BR /&gt;- /home/cisco/Ansible/vault_password2.yml&lt;BR /&gt;vars:&lt;BR /&gt;ansible_become_pass: "{{ vault_sudo_password }}"&lt;BR /&gt;ansible_python_interpreter: /usr/bin/python3&lt;/P&gt;&lt;P&gt;tasks:&lt;BR /&gt;&lt;BR /&gt;- name: show ip route and bfd neighbors prior to changes&lt;BR /&gt;ios_command:&lt;BR /&gt;commands:&lt;BR /&gt;- sh run | sec eigrp&lt;/P&gt;&lt;P&gt;become: true&lt;BR /&gt;register: output1&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;- name: "BGP: no EIGRP redist route map"&lt;BR /&gt;ios_config:&lt;BR /&gt;lines:&lt;BR /&gt;- no redistribute eigrp 10 route-map EIGRP-2-BGP&lt;BR /&gt;parents:&lt;BR /&gt;- router bgp 65411&lt;BR /&gt;- address-family ipv4&lt;BR /&gt;when: output1.stdout is search("redistribute eigrp 10 route-map EIGRP-2-BGP")&lt;BR /&gt;&lt;BR /&gt;become: true&lt;BR /&gt;register: output2&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;- name: "no router eigrp 10"&lt;BR /&gt;ios_config:&lt;BR /&gt;commands:&lt;BR /&gt;- no router eigrp 10&lt;BR /&gt;when: output1.stdout is search("router eigrp 10")&lt;BR /&gt;&lt;BR /&gt;become: true&lt;BR /&gt;register: output3&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;- name: show ip route and bfd neighbors after changes&lt;BR /&gt;ios_command:&lt;BR /&gt;commands:&lt;BR /&gt;- sh ip route vrf mgmtVrf&lt;BR /&gt;- sh ip bgp summary&lt;BR /&gt;- sh ip route&lt;BR /&gt;- sh bfd neighbors&lt;/P&gt;&lt;P&gt;become: true&lt;BR /&gt;register: output4&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;- name: print result1-show run | sec eigrp&lt;BR /&gt;debug:&lt;BR /&gt;var: output1&lt;/P&gt;&lt;P&gt;- name: print result2-BGP no EIGRP redist route map&lt;BR /&gt;debug:&lt;BR /&gt;var: output2&lt;BR /&gt;&lt;BR /&gt;- name: print result3-no router eigrp 10&lt;BR /&gt;debug:&lt;BR /&gt;var: output3&lt;BR /&gt;&lt;BR /&gt;- name: print result4-show ip route and bfd neighbors after changes&lt;BR /&gt;debug:&lt;BR /&gt;var: output4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Reduced output&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;~/Ansible$ ansible-playbook -i inventories/hosts-lab library/site-eos-eigrp-remove-when.yml -u cisco -k --ask-vault-pass&lt;BR /&gt;SSH password:&lt;BR /&gt;Vault password:&lt;/P&gt;&lt;P&gt;PLAY [Ansible ios_command on Cisco IOS XE] **********************************************************************************************************************************************************************************&lt;/P&gt;&lt;P&gt;TASK [Gathering Facts] **********************************************************************************************************************************************************************************************************************&lt;BR /&gt;ok: [10.0.0.1]&lt;/P&gt;&lt;P&gt;TASK [show ip route and bfd neighbors prior to changes] *************************************************************************************************************************************************************************************&lt;BR /&gt;ok: [10.0.0.1]&lt;/P&gt;&lt;P&gt;TASK [BGP: no EIGRP redist route map] *******************************************************************************************************************************************************************************************************&lt;BR /&gt;skipping: [10.0.0.1]&lt;/P&gt;&lt;P&gt;TASK [no router eigrp 10] *******************************************************************************************************************************************************************************************************************&lt;BR /&gt;[WARNING]: To ensure idempotency and correct diff the input configuration lines should be similar to how they appear if present in the running configuration on device&lt;BR /&gt;changed: [10.0.0.1]&lt;/P&gt;&lt;P&gt;TASK [show ip route and bfd neighbors after changes] ****************************************************************************************************************************************************************************************&lt;BR /&gt;ok: [10.0.0.1]&lt;/P&gt;&lt;P&gt;TASK [print result1-show run | sec eigrp] ***************************************************************************************************************************************************************************************************&lt;BR /&gt;ok: [10.0.0.1] =&amp;gt; {&lt;BR /&gt;"output1": {&lt;BR /&gt;"changed": false,&lt;BR /&gt;"failed": false,&lt;BR /&gt;"stdout": [&lt;BR /&gt;"router eigrp 10\n distribute-list route-map RM-EIGRP-DL-IN in \n shutdown\n redistribute eigrp 10 route-map RM-EIGRP-2-BGP"&lt;BR /&gt;],&lt;BR /&gt;"stdout_lines": [&lt;BR /&gt;[&lt;BR /&gt;"router eigrp 10",&lt;BR /&gt;" distribute-list route-map RM-EIGRP-DL-IN in ",&lt;BR /&gt;" shutdown",&lt;BR /&gt;" &lt;STRONG&gt;redistribute eigrp 10 route-map RM-EIGRP-2-BGP&lt;/STRONG&gt;"&lt;BR /&gt;]&lt;BR /&gt;]&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;TASK [print result2-BGP no EIGRP redist route map] ******************************************************************************************************************************************************************************************&lt;BR /&gt;ok: [10.0.0.1] =&amp;gt; {&lt;BR /&gt;"output2": {&lt;BR /&gt;"changed": false,&lt;BR /&gt;"false_condition": "output1.stdout is search(\"&lt;STRONG&gt;redistribute eigrp 10 route-map EIGRP-2-BGP&lt;/STRONG&gt;\")",&lt;BR /&gt;"skip_reason": "Conditional result was False",&lt;BR /&gt;"skipped": true&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;TASK [print result3-no router eigrp 10] *****************************************************************************************************************************************************************************************************&lt;BR /&gt;ok: [10.0.0.1] =&amp;gt; {&lt;BR /&gt;"output3": {&lt;BR /&gt;"banners": {},&lt;BR /&gt;"changed": true,&lt;BR /&gt;"commands": [&lt;BR /&gt;"no router eigrp 10"&lt;BR /&gt;],&lt;BR /&gt;"failed": false,&lt;BR /&gt;"updates": [&lt;BR /&gt;"no router eigrp 10"&lt;BR /&gt;],&lt;BR /&gt;"warnings": [&lt;BR /&gt;"To ensure idempotency and correct diff the input configuration lines should be similar to how they appear if present in the running configuration on device"&lt;BR /&gt;]&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;:&lt;/P&gt;&lt;P&gt;PLAY RECAP **********************************************************************************************************************************************************************************************************************************&lt;BR /&gt;10.0.0.1 : ok=8 changed=1 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Nov 2023 04:45:03 GMT</pubDate>
      <guid>https://community.cisco.com/t5/code-exchange/ansible-when-statement-based-an-previous-output/m-p/4962648#M38</guid>
      <dc:creator>Netmart</dc:creator>
      <dc:date>2023-11-20T04:45:03Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible WHen statement based an previous Output</title>
      <link>https://community.cisco.com/t5/code-exchange/ansible-when-statement-based-an-previous-output/m-p/4962716#M39</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;To me this looks okay, maybe depending on the versions you use, the regex is not matching because of the whitespace before the route-map config-line - can you try change your task to the following:&lt;/P&gt;
&lt;LI-CODE lang="c"&gt;- name: "BGP: no EIGRP redist route map"
  ios_config:
    lines:
      - no redistribute eigrp 10 route-map EIGRP-2-BGP
    parents:
      - router bgp 65411
      - address-family ipv4
  when: output1.stdout is search("\\sredistribute eigrp 10 route-map EIGRP-2-BGP")&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 20 Nov 2023 07:31:56 GMT</pubDate>
      <guid>https://community.cisco.com/t5/code-exchange/ansible-when-statement-based-an-previous-output/m-p/4962716#M39</guid>
      <dc:creator>Marcel Zehnder</dc:creator>
      <dc:date>2023-11-20T07:31:56Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible WHen statement based an previous Output</title>
      <link>https://community.cisco.com/t5/code-exchange/ansible-when-statement-based-an-previous-output/m-p/4966314#M43</link>
      <description>&lt;P&gt;Hi Marcel,&lt;/P&gt;&lt;P&gt;Thank you, but it did not work. I agree it is the double space in the string which fails the string method to fail.&lt;/P&gt;&lt;P&gt;Is there any alternative avalable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;TASK [print result2-BGP no EIGRP redist route map] *********************************************************************&lt;BR /&gt;ok: [10.254.199.199] =&amp;gt; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "output3": {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "changed": false,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "false_condition": "output2.stdout is search(\"\\\\sredistribute eigrp 10 route-map EIGRP-2-BGP\")",&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "skip_reason": "Conditional result was False",&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "skipped": true&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;}&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Nov 2023 08:31:52 GMT</pubDate>
      <guid>https://community.cisco.com/t5/code-exchange/ansible-when-statement-based-an-previous-output/m-p/4966314#M43</guid>
      <dc:creator>Netmart</dc:creator>
      <dc:date>2023-11-26T08:31:52Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible WHen statement based an previous Output</title>
      <link>https://community.cisco.com/t5/code-exchange/ansible-when-statement-based-an-previous-output/m-p/4966580#M44</link>
      <description>&lt;P&gt;I was able to solve the whitespace by using regex_search - see example below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- name: Task4 - BGP no redistribute eigrp 10 route-map EIGRP-2-BGP&lt;BR /&gt;ios_config:&lt;BR /&gt;lines:&lt;BR /&gt;- no redistribute eigrp 10 route-map EIGRP-2-BGP&lt;BR /&gt;parents:&lt;BR /&gt;- router bgp 65411&lt;BR /&gt;- address-family ipv4&lt;/P&gt;&lt;P&gt;when: "output2.stdout | regex_search('.*redistribute eigrp 10 route-map RM-EIGRP-2-BGP.*') "&lt;BR /&gt;&lt;BR /&gt;become: true&lt;BR /&gt;register: output4&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2023 06:37:52 GMT</pubDate>
      <guid>https://community.cisco.com/t5/code-exchange/ansible-when-statement-based-an-previous-output/m-p/4966580#M44</guid>
      <dc:creator>Netmart</dc:creator>
      <dc:date>2023-11-27T06:37:52Z</dc:date>
    </item>
  </channel>
</rss>

