# Behavior change with union(query('vars', item)) when used with loop|list or loop|list vs loop|flatten?

**URL:** <https://forum.ansible.com/t/behavior-change-with-union-query-vars-item-when-used-with-loop-list-or-loop-list-vs-loop-flatten/30418>\
**Category:** Ansible Project\
**Created:** [May 24, 2019, 6:49pm UTC](https://forum.ansible.com/t/behavior-change-with-union-query-vars-item-when-used-with-loop-list-or-loop-list-vs-loop-flatten/30418 "2019-05-24T18:49:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bob](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bob/32/9260_2.png) [@bob](https://forum.ansible.com/u/bob)\
**Post date:** [May 24, 2019, 6:49pm UTC](https://forum.ansible.com/t/behavior-change-with-union-query-vars-item-when-used-with-loop-list-or-loop-list-vs-loop-flatten/30418/1 "2019-05-24T18:49:52Z")

</div>

Back in May of 2018 I asked “[How to use group\_vars when managed host is in multiple groups](https://groups.google.com/d/msg/ansible-project/Tzb_cNpytD0/fB-xDIRFBAAJ)?” (see [https://groups.google.com/d/msg/ansible-project/Tzb\_cNpytD0/fB-xDIRFBAAJ](https://groups.google.com/d/msg/ansible-project/Tzb_cNpytD0/fB-xDIRFBAAJ)) and Brian Coca present an excellent solution.

I’ve been using this solution since May 2018 but in the last 2 weeks I’m seeing different behavior.

Here are the tasks:

`

- name: set chocolatey packages to remove  
set\_fact:  
chocolatey\_remove\_packages: “{{ chocolatey\_remove\_packages|union(query(‘vars’, item)) }}”  
loop: “{{ hostvars[inventory\_hostname]|select(‘match’,‘.\*chocolatey\_remove\_packages$’) | list }}”  
tags: win\_chocolatey

- debug:  
msg: “{{ chocolatey\_remove\_packages }}”  
tags: win\_chocolatey  
`

And the debug is below

`"msg": [[], ["ccleaner", "cura", "edrawings-viewer", "edrawings-viewer-2018", "malwarebytes", "uninstalltool", "veeam-endpoint-backup-free", "edrawings-viewer"], ["3cx", "firefox"] ]`

I am pretty sure I used to get

`"msg": [[ "ccleaner", "cura", "edrawings-viewer", "edrawings-viewer-2018", "malwarebytes", "uninstalltool", "veeam-endpoint-backup-free", "edrawings-viewer", "3cx", "firefox"] ]`

I think the empty list element is from the role/win\_chocolatey/vars/main.yml where I initialize the chocolatey\_remove\_packages list and that never showed up until recently

`
