On 12/1/20 5:17 PM, James Lagermann wrote:
> Have you tried to put the line in double quotes?  I'm not sure if it's always 
> required, however, some of my 'or'
> statements will not work without them so I just put all of them in double 
> quotes.
> 
>       when:  "(item.key is not regex("(Port|Vlan)")) or (item.key not in 
> po_ints)"

That might work, but in this case you need to use single quotes for the regex:

        when:  "(item.key is not regex('(Port|Vlan)')) or (item.key not in 
po_ints)"

Regards
       Racke

> 
> On Monday, November 30, 2020 at 9:15:02 AM UTC-6 colli...@gmail.com wrote:
> 
>     Hello, 
> 
>     Just thought I would uypdate.  I was not able to find the correct syntax 
> for an or in a when statement.   What I end
>     up doing, and I am sure there is a better way to do it, was create 
> separate lists then adding them together.
> 
>         - name: Create a list without Gigabit interfaces
>           set_fact:
>             exclude1: "{{ ex | reject('search', 'Giga') | list }}"
>         - name: Create a list of GigabitEthernet0/0
>           set_fact:
>             exclude2: "{{ ex | select('search', 'GigabitEthernet0/0') | list 
> }}"
> 
>         - name: Gather the Port Channel Summary
>           ansible.netcommon.cli_parse:
>             command: "show etherchannel summary"
>             parser:
>               name: ansible.netcommon.pyats
>             set_fact: eth_sum
> 
>         - name: Get the PO Channel Interfaces
>           set_fact:
>             po_ints: "{{ eth_sum.interfaces|json_query(query)|
>                         flatten }}"
>             cacheable: yes
>           vars:
>             query: '*.port_channel.port_channel_member_intfs'
> 
>         - name: Create one list to be used in a future play
>           set_fact:
>             exclude_interfaces: "{{ exclude1 + exclude2 + po_ints }}"
>             cacheable: yes
> 
> 
>     On Wed, Nov 25, 2020 at 11:42 AM J C <colli...@gmail.com> wrote:
> 
>         I apologize I did miss a line in my task when I copied.  So I used 
> the (Port|Vlan).  Which again works as a
>         single statement.  Also tried putting the statements in ()
> 
>             - name: Apply policy to the interfaces
>               cisco.ios.ios_config:
>                 parents: interface {{ item.key }}
>                 lines:
>                   - device-tracking attach-policy IPDT_POLICY
>               loop: "{{ netbrain_interface_attributes|dict2items }}"
>               when: >
>                 item.key is not regex("(Port|Vlan)")
>                 or item.key not in po_ints
> 
>             - name: Apply policy to the interfaces
>               cisco.ios.ios_config:
>                 parents: interface {{ item.key }}
>                 lines:
>                   - device-tracking attach-policy IPDT_POLICY
>               loop: "{{ netbrain_interface_attributes|dict2items }}"
>               when: >
>                 (item.key is not regex("(Port|Vlan)"))
>                 or (item.key not in po_ints)
> 
>         On Wed, Nov 25, 2020 at 10:08 AM Stefan Hornburg (Racke) 
> <ra...@linuxia.de> wrote:
> 
>             On 11/25/20 4:44 PM, colli...@gmail.com wrote:
>             > In an ansible play, is "or" not supported with conditional 
> statements? I have a task that is searching a
>             variable for 2
>             > values. The when statements work alone, but with "or" it runs 
> but doesn't do what I am expecting. Here is
>             the task, is
>             > my syntax wrong or is it just not supported? - 
>             >
>             >
>             >     - name: Apply policy to the interfaces
>             >       cisco.ios.ios_config:
>             >         parents: interface {{ item.key }}
>             >         lines:
>             >           - device-tracking attach-policy IPDT_POLICY
>             >       loop: "{{ netbrain_interface_attributes|dict2items }}"
>             >       when: >
>             >         item.key is not search("Port")
>             >         or item.key is not search("Vlan")
>             >
> 
>             Maybe you need ( ) around both conditions, but you can also use 
> (untested)
> 
>                item.key is not regex("(Port|Vlan)")
> 
>             Regards
>                    Racke
> 
>             >
>             > --
>             > 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
>             > ansible-proje...@googlegroups.com 
> <mailto:ansible-proje...@googlegroups.com>.
>             > To view this discussion on the web visit
>             > 
> https://groups.google.com/d/msgid/ansible-project/a0649fd5-6757-4e91-9424-904629aad1fdn%40googlegroups.com
>             
> <https://groups.google.com/d/msgid/ansible-project/a0649fd5-6757-4e91-9424-904629aad1fdn%40googlegroups.com>
>             >
>             
> <https://groups.google.com/d/msgid/ansible-project/a0649fd5-6757-4e91-9424-904629aad1fdn%40googlegroups.com?utm_medium=email&utm_source=footer
>             
> <https://groups.google.com/d/msgid/ansible-project/a0649fd5-6757-4e91-9424-904629aad1fdn%40googlegroups.com?utm_medium=email&utm_source=footer>>.
> 
> 
>             -- 
>             Ecommerce and Linux consulting + Perl and web application 
> programming.
>             Debian and Sympa administration. Provisioning with Ansible.
> 
>             -- 
>             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
>             ansible-proje...@googlegroups.com.
>             To view this discussion on the web visit
>             
> https://groups.google.com/d/msgid/ansible-project/81625ee8-3b31-a6b7-dc30-50b4db9b5d72%40linuxia.de
>             
> <https://groups.google.com/d/msgid/ansible-project/81625ee8-3b31-a6b7-dc30-50b4db9b5d72%40linuxia.de>.
> 
> -- 
> 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
> ansible-project+unsubscr...@googlegroups.com 
> <mailto:ansible-project+unsubscr...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/36fbffed-c622-4565-b513-455dc1034e97n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/36fbffed-c622-4565-b513-455dc1034e97n%40googlegroups.com?utm_medium=email&utm_source=footer>.


-- 
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/5beb208e-83e5-7c05-8386-b88f45c0fca5%40linuxia.de.

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to