# Filtering variables

**URL:** <https://forum.ansible.com/t/filtering-variables/29393>\
**Category:** Ansible Project\
**Created:** [January 8, 2019, 4:18pm UTC](https://forum.ansible.com/t/filtering-variables/29393 "2019-01-08T16:18:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [January 8, 2019, 4:18pm UTC](https://forum.ansible.com/t/filtering-variables/29393/1 "2019-01-08T16:18:29Z")

</div>

I am using getent to search for user details; however, I only wish for information regarding 3 users. I can’t seem to find a way to get a filter to work.

`

- debug:  
var: getent\_passwd.(‘user1’|‘user2’|‘user3’)

`

I am doing something wrong, but could use a nudge in the right direction. I know if I specify getent\_passwd.user1, I see the info just for that user… I am just trying to expand it to 3 users.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [January 8, 2019, 4:25pm UTC](https://forum.ansible.com/t/filtering-variables/29393/2 "2019-01-08T16:25:30Z")

</div>

- debug: var=getent\_passwd[item]  
&nbsp;&nbsp;with\_items:  
&nbsp;&nbsp;&nbsp;&nbsp;- user1  
&nbsp;&nbsp;&nbsp;&nbsp;- user2  
&nbsp;&nbsp;&nbsp;&nbsp;- user3

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [January 8, 2019, 4:28pm UTC](https://forum.ansible.com/t/filtering-variables/29393/3 "2019-01-08T16:28:08Z")

</div>

Perfect, thx Kai. One follow-up question. Why getent\_passwd[item] instead of getentpasswd.[item] (notice the dot)?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [January 8, 2019, 4:32pm UTC](https://forum.ansible.com/t/filtering-variables/29393/4 "2019-01-08T16:32:40Z")

</div>

getent\_passwd.user1 is the same as getent\_passwd['user1'] it's just different syntax.

But when you are using variables you need the , if not item is taken as the string "item" and not the variable item.
