# selectattr : multiples attributes "defined" ?

**URL:** <https://forum.ansible.com/t/selectattr-multiples-attributes-defined/35552>\
**Category:** Ansible Project\
**Tags:** galaxy-ng\
**Created:** [July 27, 2021, 2:04pm UTC](https://forum.ansible.com/t/selectattr-multiples-attributes-defined/35552 "2021-07-27T14:04:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gaetan\_QUENTIN](https://avatars.discourse-cdn.com/v4/letter/g/e9bcb4/32.png) [@Gaetan\_QUENTIN](https://forum.ansible.com/u/Gaetan_QUENTIN)\
**Post date:** [July 27, 2021, 2:04pm UTC](https://forum.ansible.com/t/selectattr-multiples-attributes-defined/35552/1 "2021-07-27T14:04:57Z")

</div>

Hi,

i am trying to filter a list containg items with differents attributes which may exist or not. I know to to do it with one attrobute, but how to select multiple attributes which may not exist?

exemple below can filter and get one attribute (port-tcprange) , but i need udp-portrange too and i don't know how to do it:

is there a way to make multi-attributes selection?

- name: find items from attributes tcp-portrange and udp-portrange, if they exist  
vars:  
response\_data:  
- color: 0  
udp-portrange: [5-7000]  
- color: 1  
tcp-portrange: ["1-65535"]  
udp-portrange":   
- color: 2  
tcp-portrange: ["12"]  
- color: 3  
galaxy: "andromeda"  
set\_fact:  
y: "{{ response\_data | selectattr('tcp-portrange', 'defined') | map(attribute='tcp-portrange') | flatten}}"  
tags:  
- test-regles3-3  
- name: show y  
debug:  
msg: "valeur de y: {{ y }}"  
tags:  
- test-regles3-3

results: ['1-65535', '12']"
