<?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 Re: Ansible using Loop with registered variables in DevNet General Discussions</title>
    <link>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5128413#M2432</link>
    <description>&lt;P&gt;Loop control should not contain the loop itself, only other "loop parameters". You can try this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;     - name: Task2 - sh run
       ios_command:
          commands:
              - sh run | i "{{ item.prefix }}"  
       loop: "{{ prefix_list }}"
       loop_control:
         loop_vars: "{{ item.prefix }}"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Jun 2024 08:25:24 GMT</pubDate>
    <dc:creator>Torbjørn</dc:creator>
    <dc:date>2024-06-11T08:25:24Z</dc:date>
    <item>
      <title>Ansible using Loop with registered variables</title>
      <link>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5101630#M2423</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I was wondering, whether it is possible instead of creating three separate tasks, one processing one element of an array, to actually loop through an array.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;vars&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;ansible_become_pass&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"{{ vault_sudo_password }}"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;ansible_python_interpreter&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;/usr/bin/python3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;prefix&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;10.0.1.0/25&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;10.0.3.0/25&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;10.0.5.0/25&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;- &lt;/SPAN&gt;&lt;SPAN&gt;name&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;Task1- remove prefix&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;ios_config&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;commands&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- &lt;/SPAN&gt;&lt;SPAN&gt;no ip prefix-list MTDC-nets permit &lt;/SPAN&gt;&lt;SPAN&gt;{{prefix[0]}}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;when&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;output2.stdout is search &lt;/SPAN&gt;&lt;SPAN&gt;~prefix[0] &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;become&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;true&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;register&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;output1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;- &lt;/SPAN&gt;&lt;SPAN&gt;name&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;Task2- remove prefix&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;ios_config&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;commands&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- &lt;/SPAN&gt;&lt;SPAN&gt;no ip prefix-list cisco-nets permit &lt;/SPAN&gt;&lt;SPAN&gt;{{prefix[1]}}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;when&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;output2.stdout is search &lt;/SPAN&gt;&lt;SPAN&gt;~prefix[1] &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;become&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;true&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;register&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;output2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;- &lt;/SPAN&gt;&lt;SPAN&gt;name&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;Task3- remove prefix&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;ios_config&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;commands&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- &lt;/SPAN&gt;&lt;SPAN&gt;no ip prefix-list MTDC-nets permit &lt;/SPAN&gt;&lt;SPAN&gt;{{prefix[2]}}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;when&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;output2.stdout is search &lt;/SPAN&gt;&lt;SPAN&gt;~prefix[2] &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;become&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;true&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;register&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;output3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to create only one task and looping through the elements of an array:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;vars&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;ansible_become_pass&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"{{ vault_sudo_password }}"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;ansible_python_interpreter&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;/usr/bin/python3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;loop:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;10.0.1.0/25&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;10.0.3.0/25&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;10.0.5.0/25&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;register: prefix&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;- &lt;/SPAN&gt;&lt;SPAN&gt;name&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;Task1- remove prefix&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;ios_config&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;commands&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- &lt;/SPAN&gt;&lt;SPAN&gt;no ip prefix-list Cisco-nets permit &lt;/SPAN&gt;&lt;SPAN&gt;{{prefix}}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;when&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;output2.stdout is search &lt;/SPAN&gt;&lt;SPAN&gt;~prefix&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;become&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;true&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;register&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;output1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2024 23:22:59 GMT</pubDate>
      <guid>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5101630#M2423</guid>
      <dc:creator>Netmart</dc:creator>
      <dc:date>2024-05-10T23:22:59Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible using Loop with registered variables</title>
      <link>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5101891#M2424</link>
      <description>&lt;P&gt;You can, instead of creating separate tasks for each element in the array, use a single task with a loop. Then use a&amp;nbsp;&lt;SPAN&gt;dictionary to store the prefix list and its corresponding network name.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;---&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;prefix_list:&lt;BR /&gt;- { network: "MTDC-nets", prefix: "10.0.1.0/25" }&lt;BR /&gt;- { network: "cisco-nets", prefix: "10.0.3.0/25" }&lt;BR /&gt;- { network: "MTDC-nets", prefix: "10.0.5.0/25" }&lt;/P&gt;
&lt;P&gt;tasks:&lt;BR /&gt;- name: Remove prefix&lt;BR /&gt;ios_config:&lt;BR /&gt;commands:&lt;BR /&gt;- "no ip prefix-list {{ item.network }} permit {{ item.prefix }}"&lt;BR /&gt;when: output2.stdout is search ~item.prefix&lt;BR /&gt;become: true&lt;BR /&gt;register: output&lt;BR /&gt;loop: "{{ prefix_list }}"&lt;/P&gt;</description>
      <pubDate>Sat, 11 May 2024 07:04:57 GMT</pubDate>
      <guid>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5101891#M2424</guid>
      <dc:creator>bigevilbeard</dc:creator>
      <dc:date>2024-05-11T07:04:57Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible using Loop with registered variables</title>
      <link>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5103776#M2425</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;I tried to apply it, but it seems still to be an error&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; prefix_list:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- &amp;nbsp;{network:"Test-nets",prefix:"10.0.0.0/25"}&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- &amp;nbsp;{network:"Test-nets",prefix:"10.0.2.0/25"}&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- &amp;nbsp;{network:"Test-nets",prefix:"10.0.5.0/25"}&lt;/P&gt;&lt;P&gt;:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;- name: Task2 - sh run&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ios_command:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; commands:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; - "sh run | i Test-nets"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;become: true&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;register: output2&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;BR /&gt;:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;- name: Task3- remove prefix&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ios_config:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;commands:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- "no ip prefix-list {{ item.network }} permit {{ item.prefix }}"&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;when: output2.stdout is search ~item.prefix&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;become: true&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;register: output3&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;loop: "{{ prefix_list }}"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;\nThe offending line appears to be:\n\n\n&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - name: Task3- remove prefix\n&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ^ here\n"&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;BR /&gt;TASK [Task3- remove prefix] ********************************************************************************************&lt;/P&gt;&lt;P&gt;fatal: [cisco.org]: FAILED! =&amp;gt; {"msg": "The conditional check 'output2.stdout is search ~item.prefix' failed.&lt;BR /&gt;The error was: error while evaluating conditional (output2.stdout is search ~item.prefix):&lt;BR /&gt;'dict object' has no attribute 'stdout'. 'dict object' has no attribute 'stdout'\n\nThe error appears to be in&lt;BR /&gt;'/home/cisco/Ansible/library/lib-ios-xe-staging/site-ios-xe-CE-bgp-prefix-list-update-loop.yml': line 39, column 8,&lt;BR /&gt;but may\nbe elsewhere in the file depending on the exact syntax problem.\n&lt;/P&gt;</description>
      <pubDate>Mon, 13 May 2024 16:52:40 GMT</pubDate>
      <guid>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5103776#M2425</guid>
      <dc:creator>Netmart</dc:creator>
      <dc:date>2024-05-13T16:52:40Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible using Loop with registered variables</title>
      <link>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5103806#M2426</link>
      <description>&lt;P&gt;Looks like the the&lt;SPAN&gt;&amp;nbsp;error is due to the &lt;/SPAN&gt;&lt;CODE&gt;when&lt;/CODE&gt;&lt;SPAN&gt; condition in Task3. The &lt;/SPAN&gt;&lt;CODE&gt;output2&lt;/CODE&gt;&lt;SPAN&gt; variable is not accessible in the scope of Task3. &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Try and use the &lt;/SPAN&gt;&lt;CODE&gt;output&lt;/CODE&gt;&lt;SPAN&gt; variable from Task2 to check the prefix.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 May 2024 17:21:48 GMT</pubDate>
      <guid>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5103806#M2426</guid>
      <dc:creator>bigevilbeard</dc:creator>
      <dc:date>2024-05-13T17:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible using Loop with registered variables</title>
      <link>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5110535#M2427</link>
      <description>&lt;P&gt;It seems that it is already complaining at Task2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TASK [Task2 - sh run] **********************************************************************************************************************&lt;BR /&gt;fatal: [cisco.org]: FAILED! =&amp;gt; {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'prefix'. 'dict object'&lt;BR /&gt;has no attribute 'prefix'\n\nThe error appears to be in '/home/cisco/Ansible/library/lib-ios-xe-staging/site-ios-xe-CE-bgp-prefix-list-update-loop.yml':&lt;BR /&gt;line 28, column 8, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Task2 - sh run\n ^ here\n"}&lt;/P&gt;&lt;P&gt;PLAY RECAP *********************************************************************************************************************************&lt;BR /&gt;cisco.org : ok=2 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;site-ios-xe-CE-bgp-prefix-list-update-loop.yml&lt;/P&gt;&lt;P&gt;:&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;prefix_list:&lt;BR /&gt;- {network:"Test-nets",prefix:"10.0.0.0/25"}&lt;BR /&gt;- {network:"Test-nets",prefix:"10.0.2.0/25"}&lt;BR /&gt;- {network:"Test-nets",prefix:"10.0.5.0/25"}&lt;/P&gt;&lt;P&gt;tasks:&lt;BR /&gt;&lt;BR /&gt;- name: Task1 - sh run | count Test-nets&lt;BR /&gt;ios_command:&lt;BR /&gt;commands:&lt;BR /&gt;- sh run | count Test-nets&lt;/P&gt;&lt;P&gt;become: true&lt;BR /&gt;register: output1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- name: Task2 - sh run [ line 28, column 8,]&lt;BR /&gt;ios_command:&lt;BR /&gt;commands:&lt;BR /&gt;- sh run | i {{ item.prefix }}&lt;/P&gt;&lt;P&gt;become: true&lt;BR /&gt;register: output2&lt;BR /&gt;loop: "{{ prefix_list }}"&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;- name: Task3- remove prefix&lt;BR /&gt;ios_config:&lt;BR /&gt;commands:&lt;BR /&gt;- "no ip prefix-list {{ item.network }} permit {{ item.prefix }}"&lt;BR /&gt;when: output2.stdout is search ~item.prefix&lt;/P&gt;&lt;P&gt;become: true&lt;BR /&gt;register: output2&lt;BR /&gt;loop: "{{ prefix_list }}"&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;- name: Task4 check prefix has been removed&lt;BR /&gt;ios_command:&lt;BR /&gt;commands:&lt;BR /&gt;- "sh run | i {{ item.prefix }}"&lt;/P&gt;&lt;P&gt;become: true&lt;BR /&gt;register: output4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- name: Task5 - sh run | count Test-nets&lt;BR /&gt;ios_command:&lt;BR /&gt;commands:&lt;BR /&gt;- sh run | count Test-nets&lt;/P&gt;&lt;P&gt;become: true&lt;BR /&gt;register: output5&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# ******** Output results ********&lt;BR /&gt;&lt;BR /&gt;- name: Result1 prefix count prior to update - sh run | count TestC-nets&lt;BR /&gt;debug:&lt;BR /&gt;var: output1&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;- name: Result2.1 check if prefix is configured&lt;BR /&gt;debug:&lt;BR /&gt;msg: " Prefix is configured @ {{inventory_hostname}}: {{ item.network }} permit {{ item.prefix }}"&lt;BR /&gt;when: output2.stdout is search {{ item.network }} permit {{ item.prefix }}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;- name: Result2.2 check if prefix is NOT oonfigured&lt;BR /&gt;debug:&lt;BR /&gt;msg: " Prefix is configured @ {{inventory_hostname}}: {{ item.network }} permit {{ item.prefix }}"&lt;BR /&gt;when: output2.stdout is not search {{ item.network }} permit {{ item.prefix }}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- name: Result4 check if prefix has been removed&lt;BR /&gt;debug:&lt;BR /&gt;msg: " Prefix has been removed @ {{inventory_hostname}}: {{ item.network }} permit {{ item.prefix }}"&lt;BR /&gt;when: output4.stdout is not search {{ item.network }} permit {{ item.prefix }}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;- name: Result5 prefix count post to update - sh run | count Test-nets&lt;BR /&gt;debug:&lt;BR /&gt;var: output5&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2024 04:51:49 GMT</pubDate>
      <guid>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5110535#M2427</guid>
      <dc:creator>Netmart</dc:creator>
      <dc:date>2024-05-20T04:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible using Loop with registered variables</title>
      <link>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5110646#M2428</link>
      <description>&lt;P&gt;Got it, try by a&lt;SPAN&gt;dding &lt;/SPAN&gt;&lt;SPAN&gt;loop_var&lt;/SPAN&gt;&lt;SPAN&gt;: item&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;- name: Task2 - sh run
  ios_command:
    commands:
      - sh run | i {{ item.prefix }}
    become: true
  register: output2
  loop: "{{ prefix_list }}"
  loop_var: item&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2024 07:45:10 GMT</pubDate>
      <guid>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5110646#M2428</guid>
      <dc:creator>bigevilbeard</dc:creator>
      <dc:date>2024-05-20T07:45:10Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible using Loop with registered variables</title>
      <link>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5116773#M2429</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;I tried, but...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ERROR! conflicting action statements: &lt;/STRONG&gt;&lt;STRONG&gt;ios_command&lt;/STRONG&gt;&lt;STRONG&gt;, &lt;/STRONG&gt;&lt;STRONG&gt;loop_vars&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The error appears to be in '/home/cisco/Ansible/library/lib-ios-xe-staging/site-ios-xe-CE-bgp-prefix-list-update-loop.yml': line 30, column 8, but may&lt;/P&gt;&lt;P&gt;be elsewhere in the file depending on the exact syntax problem.&lt;/P&gt;&lt;P&gt;The offending line appears to be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - name: Task2 - sh run&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ^ here0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;======================&lt;/P&gt;&lt;P&gt;Extract playbook:&lt;/P&gt;&lt;P&gt;site-ios-xe-CE-bgp-prefix-list-update-loop.yml&lt;/P&gt;&lt;P&gt;:&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;prefix_list:&lt;BR /&gt;- {network:"Test-nets",prefix:"10.0.0.0/25"}&lt;BR /&gt;- {network:"Test-nets",prefix:"10.0.2.0/25"}&lt;BR /&gt;- {network:"Test-nets",prefix:"10.0.5.0/25"}&lt;/P&gt;&lt;P&gt;tasks:&lt;BR /&gt;&lt;BR /&gt;- name: Task1 - sh run | count Test-nets&lt;BR /&gt;ios_command:&lt;BR /&gt;commands:&lt;BR /&gt;- sh run | count Test-nets&lt;/P&gt;&lt;P&gt;become: true&lt;BR /&gt;register: output1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- name: Task2 - sh run [ line 30,column 8,]&lt;BR /&gt;ios_command:&lt;BR /&gt;commands:&lt;BR /&gt;- sh run | i {{ item.prefix }}&lt;/P&gt;&lt;P&gt;become: true&lt;BR /&gt;register: output2&lt;BR /&gt;loop: "{{ prefix_list }}“&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;loop_var&lt;/STRONG&gt;&lt;STRONG&gt;: item&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 26 May 2024 03:36:48 GMT</pubDate>
      <guid>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5116773#M2429</guid>
      <dc:creator>Netmart</dc:creator>
      <dc:date>2024-05-26T03:36:48Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible using Loop with registered variables</title>
      <link>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5116890#M2430</link>
      <description>&lt;P&gt;&lt;SPAN&gt;For your error message is indicating that there is a conflict between the &lt;/SPAN&gt;&lt;CODE&gt;ios_command&lt;/CODE&gt;&lt;SPAN&gt; and &lt;/SPAN&gt;&lt;CODE&gt;loop_vars&lt;/CODE&gt;&lt;SPAN&gt; directives in the "Task2". &amp;nbsp;I would suggest&amp;nbsp;move the &lt;CODE&gt;loop_var&lt;/CODE&gt; directive inside the &lt;CODE&gt;loop_control&lt;/CODE&gt; block.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Hope this helps.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 May 2024 10:30:41 GMT</pubDate>
      <guid>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5116890#M2430</guid>
      <dc:creator>bigevilbeard</dc:creator>
      <dc:date>2024-05-26T10:30:41Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible using Loop with registered variables</title>
      <link>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5128212#M2431</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;I tried the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;vars&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;ansible_become_pass&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"{{ vault_sudo_password }}"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;ansible_python_interpreter&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;/usr/bin/python3&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;network&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"{{ item.network }}"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;prefix&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"{{ item.prefix }}"&lt;/SPAN&gt;&lt;SPAN&gt; &amp;nbsp; &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;prefix_list&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- {&lt;/SPAN&gt;&lt;SPAN&gt;network:"Test-nets"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;prefix:"10.0.0.0/25"&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- {&lt;/SPAN&gt;&lt;SPAN&gt;network:"Test-nets"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;prefix:"10.0.2.0/25"&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- {&lt;/SPAN&gt;&lt;SPAN&gt;network:"Test-nets"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;prefix:"10.0.5.0/25"&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;- &lt;/SPAN&gt;&lt;SPAN&gt;name&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;Task2 - sh run&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;ios_command&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;commands&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; - &lt;/SPAN&gt;&lt;SPAN&gt;sh run | i "{{ item.prefix }}"&lt;/SPAN&gt;&lt;SPAN&gt; &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;loop_control&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;loop&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"{{ prefix_list }}"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;loop_vars&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"{{ item.prefix }}"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;And received the following error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR! 'loop' is not a valid attribute for a LoopControl&lt;/P&gt;&lt;P&gt;The error appears to be in '/home/cisco/Ansible/library/lib-ios-xe-staging/site-ios-xe-CE-bgp-prefix-list-update-loop2.yml': line 40, column 10, but may&lt;BR /&gt;be elsewhere in the file depending on the exact syntax problem.&lt;/P&gt;&lt;P&gt;The offending line appears to be:&lt;/P&gt;&lt;P&gt;loop_control:&lt;BR /&gt;loop: "{{ prefix_list }}"&lt;BR /&gt;^ here&lt;BR /&gt;We could be wrong, but this one looks like it might be an issue with&lt;BR /&gt;missing quotes. Always quote template expression brackets when they&lt;BR /&gt;start a value. For instance:&lt;/P&gt;&lt;P&gt;with_items:&lt;BR /&gt;- {{ foo }}&lt;/P&gt;&lt;P&gt;Should be written as:&lt;/P&gt;&lt;P&gt;with_items:&lt;BR /&gt;- "{{ foo }}"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would appreciate any advice.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jun 2024 20:24:02 GMT</pubDate>
      <guid>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5128212#M2431</guid>
      <dc:creator>Netmart</dc:creator>
      <dc:date>2024-06-10T20:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible using Loop with registered variables</title>
      <link>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5128413#M2432</link>
      <description>&lt;P&gt;Loop control should not contain the loop itself, only other "loop parameters". You can try this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;     - name: Task2 - sh run
       ios_command:
          commands:
              - sh run | i "{{ item.prefix }}"  
       loop: "{{ prefix_list }}"
       loop_control:
         loop_vars: "{{ item.prefix }}"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2024 08:25:24 GMT</pubDate>
      <guid>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5128413#M2432</guid>
      <dc:creator>Torbjørn</dc:creator>
      <dc:date>2024-06-11T08:25:24Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible using Loop with registered variables</title>
      <link>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5132359#M2433</link>
      <description>&lt;P&gt;Hi Torbjoern,&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;I tried, but it seems to still have an issue:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FAILED! =&amp;gt; {"msg": "The field 'loop_var' has an invalid value, which includes an undefined variable. The error was: 'item' is undefined. 'item' is undefined\n\nThe error appears to be in '/home/cisco/Ansible/library/lib-ios-xe-staging/site-ios-xe-CE-bgp-prefix-list-update-loop2.yml': line 40, column 11, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n loop_control:\n loop_var: \"{{item.prefix}}\"\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with_items:\n - {{ foo }}\n\nShould be written as:\n\n with_items:\n - \"{{ foo }}\"\n"}&lt;/P&gt;&lt;P&gt;Please advise.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 04:41:02 GMT</pubDate>
      <guid>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5132359#M2433</guid>
      <dc:creator>Netmart</dc:creator>
      <dc:date>2024-06-17T04:41:02Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible using Loop with registered variables</title>
      <link>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5133041#M2434</link>
      <description>&lt;P&gt;After reading over this again - sorry, my last response wasn't a good response to the original question asked. It was only answering to the specific syntax error you posted.&lt;/P&gt;&lt;P&gt;The simplest way to do this would be to do something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;     - name: Remove prefix
        ios_command:
          commands:
          - "no ip prefix-list {{ item.name }} permit {{ item.prefix }}"  
        loop: "{{ prefix_list }}"
      &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you need to verify that the prefix-list entry exists before removing like in your original playbook you can do something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;     - name: Get running-config
        ios_command: 
        - "show running-config"
        register: running_config
     - name: Remove prefix
        ios_command:
          commands:
          - "no ip prefix-list {{ item.name }} permit {{ item.prefix }}"  
        loop: "{{ prefix_list }}"
        when: running_config.stdout is search(item.name) | running_config.stdout is search(item.prefix)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2024 09:02:11 GMT</pubDate>
      <guid>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5133041#M2434</guid>
      <dc:creator>Torbjørn</dc:creator>
      <dc:date>2024-06-18T09:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible using Loop with registered variables</title>
      <link>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5133733#M2438</link>
      <description>&lt;P&gt;Thank you Torbjoern.&lt;/P&gt;&lt;P&gt;The issues remains the same:&lt;/P&gt;&lt;P&gt;The error appears to be in '/home/cisco/Ansible/library/lib-ios-xe-staging/site-ios-xe-CE-bgp-prefix-list-update-loop2.yml': line 44, column 9, but may&lt;BR /&gt;be elsewhere in the file depending on the exact syntax problem.&lt;/P&gt;&lt;P&gt;The offending line appears to be:&lt;/P&gt;&lt;P&gt;- "no ip prefix-list {{ item.network }} permit {{ item.prefix }}"&lt;BR /&gt;loop: "{{ prefix_list }}"&lt;BR /&gt;^ here&lt;BR /&gt;We could be wrong, but this one looks like it might be an issue with&lt;BR /&gt;missing quotes. Always quote template expression brackets when they&lt;BR /&gt;start a value. For instance:&lt;/P&gt;&lt;P&gt;with_items:&lt;BR /&gt;- {{ foo }}&lt;/P&gt;&lt;P&gt;Should be written as:&lt;/P&gt;&lt;P&gt;with_items:&lt;BR /&gt;- "{{ foo }}"&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2024 19:24:19 GMT</pubDate>
      <guid>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5133733#M2438</guid>
      <dc:creator>Netmart</dc:creator>
      <dc:date>2024-06-19T19:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible using Loop with registered variables</title>
      <link>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5133756#M2439</link>
      <description>&lt;DIV class=""&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;vars:&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;prefix_list&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- {&lt;/SPAN&gt;&lt;SPAN&gt;network:"Test-nets"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;prefix:"10.0.0.0/25"&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- {&lt;/SPAN&gt;&lt;SPAN&gt;network:"Test-nets"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;prefix:"10.0.2.0/25"&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- {&lt;/SPAN&gt;&lt;SPAN&gt;network:"Test-nets"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;prefix:"10.0.5.0/25"&lt;/SPAN&gt;&lt;SPAN&gt;} &lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;tasks&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;- &lt;/SPAN&gt;&lt;SPAN&gt;name&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;Task3 - remove prefix&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;ios_config&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;commands&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; - &lt;/SPAN&gt;&lt;SPAN&gt;"no ip prefix-list {{ item.network }} permit {{ item.prefix }}"&lt;/SPAN&gt;&lt;SPAN&gt; &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;loop&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"{{ prefix_list }}"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;loop_control&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;loop_var&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;prefix_list&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I get:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;FAILED! =&amp;gt;&lt;BR /&gt;{"msg": "The task includes an option with an undefined variable.&lt;BR /&gt;The error was: 'item' is undefined. 'item' is undefined\n\nThe error appears to be in&lt;BR /&gt;'/home/cisco/Ansible/library/lib-ios-xe-staging/site-ios-xe-CE-bgp-prefix-list-update-loop2.yml':&lt;BR /&gt;line 36, column 8, but may\nbe elsewhere in the file depending on the exact syntax problem.&lt;BR /&gt;\n\nThe offending line appears to be:\n\n\n - name: Task3 - remove prefix\n ^ here\n"}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 19 Jun 2024 20:18:06 GMT</pubDate>
      <guid>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5133756#M2439</guid>
      <dc:creator>Netmart</dc:creator>
      <dc:date>2024-06-19T20:18:06Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible using Loop with registered variables</title>
      <link>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5134012#M2440</link>
      <description>&lt;P&gt;I believe this should work if you remove the whole "loop_control:" portion.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2024 11:31:05 GMT</pubDate>
      <guid>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5134012#M2440</guid>
      <dc:creator>Torbjørn</dc:creator>
      <dc:date>2024-06-20T11:31:05Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible using Loop with registered variables</title>
      <link>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5137765#M2459</link>
      <description>&lt;P&gt;Sorry Torbjoern, this has been already tried without success.&lt;/P&gt;&lt;P&gt;Is there no example available illustrating looping through an array as in my case.&lt;/P&gt;&lt;P&gt;The material I"ve found so far in Ansible is not really matching what I am looking for.&lt;/P&gt;&lt;P&gt;The closest I was able to find has been:&lt;/P&gt;&lt;H3&gt;&lt;A href="https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_loops.html#id6" target="_blank" rel="noopener"&gt;Iterating over a list of hashes&lt;/A&gt;&lt;A title="Link to this heading" href="https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_loops.html#iterating-over-a-list-of-hashes" target="_blank" rel="noopener"&gt;&lt;/A&gt;&lt;/H3&gt;&lt;P&gt;If you have a list of hashes, you can reference subkeys in a loop. For example:&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;-&lt;/SPAN&gt; &lt;SPAN class=""&gt;name&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt; &lt;SPAN class=""&gt;Add several users&lt;/SPAN&gt;
  &lt;SPAN class=""&gt;ansible.builtin.user&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt;
    &lt;SPAN class=""&gt;name&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt; &lt;SPAN class=""&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;{{&lt;/SPAN&gt; &lt;SPAN class=""&gt;item.name&lt;/SPAN&gt; &lt;SPAN class=""&gt;}}&lt;/SPAN&gt;&lt;SPAN class=""&gt;"&lt;/SPAN&gt;
    &lt;SPAN class=""&gt;state&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt; &lt;SPAN class=""&gt;present&lt;/SPAN&gt;
    &lt;SPAN class=""&gt;groups&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt; &lt;SPAN class=""&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;{{&lt;/SPAN&gt; &lt;SPAN class=""&gt;item.groups&lt;/SPAN&gt; &lt;SPAN class=""&gt;}}&lt;/SPAN&gt;&lt;SPAN class=""&gt;"&lt;/SPAN&gt;
  &lt;SPAN class=""&gt;loop&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt;
    &lt;SPAN class=""&gt;-&lt;/SPAN&gt; &lt;SPAN class=""&gt;{&lt;/SPAN&gt;&lt;SPAN class=""&gt; name&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt; &lt;SPAN class=""&gt;'testuser1'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;&lt;SPAN class=""&gt; groups&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt; &lt;SPAN class=""&gt;'wheel'&lt;/SPAN&gt; &lt;SPAN class=""&gt;}&lt;/SPAN&gt;
    &lt;SPAN class=""&gt;-&lt;/SPAN&gt; &lt;SPAN class=""&gt;{&lt;/SPAN&gt;&lt;SPAN class=""&gt; name&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt; &lt;SPAN class=""&gt;'testuser2'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;&lt;SPAN class=""&gt; groups&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt; &lt;SPAN class=""&gt;'root'&lt;/SPAN&gt; &lt;SPAN class=""&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_loops.html&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2024 21:54:15 GMT</pubDate>
      <guid>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5137765#M2459</guid>
      <dc:creator>Netmart</dc:creator>
      <dc:date>2024-06-28T21:54:15Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible using Loop with registered variables</title>
      <link>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5137832#M2460</link>
      <description>&lt;P&gt;Hi Torbjorn,&lt;/P&gt;&lt;P&gt;I am sorry, it is still failing.&lt;/P&gt;&lt;P&gt;I also tried the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;- name: Task3- remove prefix&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ios_config:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;commands:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- "no ip prefix-list {{ item.network }&lt;SPAN&gt;}&lt;/SPAN&gt; permit {{ item.prefix }&lt;SPAN&gt;}&lt;/SPAN&gt;"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;loop:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- network:"Test-nets",prefix:"10.0.0.0/25"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- network:"Test-nets",prefix:"10.0.2.0/25"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- network:"Test-nets",prefix:"10.0.5.0/25"&lt;/P&gt;&lt;P&gt;However, Ansible is still complaining that has no attribute network and prefix. And following the Ansible documentation, the loop is configured underneath the task.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;fatal: [switch: FAILED! =&amp;gt; {"msg": "The task includes an option with an undefined variable. The error was: 'ansible.parsing.yaml.objects.AnsibleUnicode object' has no attribute 'network'. 'ansible.parsing.yaml.objects.AnsibleUnicode object' has no attribute 'network'\n\nThe error appears to be in '/home/cisco/Ansible/library/lib-ios-xe-staging/site-ios-xe-CE-bgp-prefix-list-update-loop2.yml': line 34, column 8, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - name: Task3- remove prefix\n&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ^ here\n"}&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jun 2024 05:54:14 GMT</pubDate>
      <guid>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5137832#M2460</guid>
      <dc:creator>Netmart</dc:creator>
      <dc:date>2024-06-29T05:54:14Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible using Loop with registered variables</title>
      <link>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5137840#M2461</link>
      <description>&lt;P&gt;Sorry, still the same.&lt;/P&gt;&lt;P&gt;I also tried the following:&lt;/P&gt;&lt;P&gt;Extract Playbook:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;- name: Task3- remove prefix&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ios_config:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;commands:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- "no ip prefix-list {{ item.network }&lt;SPAN&gt;}&lt;/SPAN&gt; permit {{ item.prefix }&lt;SPAN&gt;}&lt;/SPAN&gt;"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;loop:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- { network:"Test-nets",prefix:"10.0.0.0/25" }&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- { network:"Test-nets",prefix:"10.0.2.0/25" }&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- { network:"Test-nets",prefix:"10.0.5.0/25" }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;fatal: [switch: FAILED! =&amp;gt; {"msg": "The task includes an option with an undefined variable. The error was: 'ansible.parsing.yaml.objects.AnsibleUnicode object' has no attribute 'network'. 'ansible.parsing.yaml.objects.AnsibleUnicode object' has no attribute 'network'\n\nThe error appears to be in '/home/cisco/Ansible/library/lib-ios-xe-staging/site-ios-xe-CE-bgp-prefix-list-update-loop2.yml': line 34, column 8, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - name: Task3- remove prefix\n&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ^ here\n"}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The previous setup follows the example as illustrated in the Ansible documentation. The only difference that I am using the ios_config command to iterate a command with a loop variable.&lt;/P&gt;&lt;H3&gt;&lt;A title="https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_loops.html#id6" href="https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_loops.html#id6" target="_blank" rel="noreferrer noopener"&gt;Iterating over a list of hashes&lt;/A&gt;&lt;A title="https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_loops.html#iterating-over-a-list-of-hashes" href="https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_loops.html#iterating-over-a-list-of-hashes" target="_blank" rel="noreferrer noopener"&gt;&lt;/A&gt;&lt;/H3&gt;&lt;P&gt;If you have a list of hashes, you can reference subkeys in a loop. For example:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;-&lt;/SPAN&gt; &lt;SPAN class=""&gt;name&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt; &lt;SPAN class=""&gt;Add several users&lt;/SPAN&gt;
  &lt;SPAN class=""&gt;ansible.builtin.user&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt;
    &lt;SPAN class=""&gt;name&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt; &lt;SPAN class=""&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;{{&lt;/SPAN&gt; &lt;SPAN class=""&gt;item.name&lt;/SPAN&gt; &lt;SPAN class=""&gt;}}&lt;/SPAN&gt;&lt;SPAN class=""&gt;"&lt;/SPAN&gt;
    &lt;SPAN class=""&gt;state&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt; &lt;SPAN class=""&gt;present&lt;/SPAN&gt;
    &lt;SPAN class=""&gt;groups&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt; &lt;SPAN class=""&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;{{&lt;/SPAN&gt; &lt;SPAN class=""&gt;item.groups&lt;/SPAN&gt; &lt;SPAN class=""&gt;}}&lt;/SPAN&gt;&lt;SPAN class=""&gt;"&lt;/SPAN&gt;
  &lt;SPAN class=""&gt;loop&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt;
    &lt;SPAN class=""&gt;-&lt;/SPAN&gt; &lt;SPAN class=""&gt;{&lt;/SPAN&gt;&lt;SPAN class=""&gt; name&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt; &lt;SPAN class=""&gt;'testuser1'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;&lt;SPAN class=""&gt; groups&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt; &lt;SPAN class=""&gt;'wheel'&lt;/SPAN&gt; &lt;SPAN class=""&gt;}&lt;/SPAN&gt;
    &lt;SPAN class=""&gt;-&lt;/SPAN&gt; &lt;SPAN class=""&gt;{&lt;/SPAN&gt;&lt;SPAN class=""&gt; name&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt; &lt;SPAN class=""&gt;'testuser2'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;&lt;SPAN class=""&gt; groups&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt; &lt;SPAN class=""&gt;'root'&lt;/SPAN&gt; &lt;SPAN class=""&gt;}&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jun 2024 06:34:34 GMT</pubDate>
      <guid>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5137840#M2461</guid>
      <dc:creator>Netmart</dc:creator>
      <dc:date>2024-06-29T06:34:34Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible using Loop with registered variables</title>
      <link>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5139807#M2466</link>
      <description>&lt;P&gt;After reviewing it together with someone from Ansible Community, it turned out that the syntax for loop was not correct:&lt;/P&gt;&lt;P&gt;A space is needed after each ‘:’ and ‘,’ in the dictionary. Tip: use ``` before and after a block of YAML/code to make it easier to read.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is working as followed:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;- ios_config:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;commands:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- "no ip prefix-list {{ item.network }} permit {{ item.prefix }}"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;loop:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;- { network: Test-nets, prefix: "10.0.0.0/25" }&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;- { network: Test-nets, prefix: "10.0.2.0/25" }&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;- { network: Test-nets, prefix: "10.0.5.0/25" }&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2024 05:56:24 GMT</pubDate>
      <guid>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5139807#M2466</guid>
      <dc:creator>netmart2</dc:creator>
      <dc:date>2024-07-04T05:56:24Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible using Loop with registered variables</title>
      <link>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5139809#M2467</link>
      <description>&lt;P&gt;The same is illustrated in Ansible documetation:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Iterating over a list of hashes&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;If you have a list of hashes, you can reference subkeys in a loop. For example:&lt;/P&gt;&lt;P&gt;- name: Add several users&lt;/P&gt;&lt;P&gt;&amp;nbsp; ansible.builtin.user:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; name: "{{ &lt;STRONG&gt;item&lt;/STRONG&gt;.&lt;STRONG&gt;name&lt;/STRONG&gt; }}"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; state: present&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; groups: "{{ &lt;STRONG&gt;item.&lt;/STRONG&gt;&lt;STRONG&gt;groups&lt;/STRONG&gt; }}"&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; loop:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; - {&lt;STRONG&gt; name&lt;/STRONG&gt;: 'testuser1', &lt;STRONG&gt;groups&lt;/STRONG&gt;: 'wheel' }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; - { name: 'testuser2', groups: 'root' }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_loops.html" target="_blank"&gt;https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_loops.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2024 05:57:51 GMT</pubDate>
      <guid>https://community.cisco.com/t5/devnet-general-discussions/ansible-using-loop-with-registered-variables/m-p/5139809#M2467</guid>
      <dc:creator>netmart2</dc:creator>
      <dc:date>2024-07-04T05:57:51Z</dc:date>
    </item>
  </channel>
</rss>

