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) 
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

---
# vars file for roles/win_chocolatey


# Initialize variable
#
chocolatey_remove_packages: []

And the 

        [
            "ccleaner",
            "cura",
            "edrawings-viewer",
            "edrawings-viewer-2018",
            "malwarebytes",
            "uninstalltool",
            "veeam-endpoint-backup-free",
            "edrawings-viewer"
        ],


Is from my corporate wide variable and 

        [
            "3cx",
            "firefox"
        ]

    
Is from my group_vars

So my question is did something change with union(query('vars', item)) 
 when used with loop | list ?

I've tried loop | flatten(levels=1) no difference.

Things continue to work with unusual output.

TASK [win_chocolatey : remove old/deprecated packages (choco)] 
*****************
ok: [appserver] => (item=[])
ok: [appserver] => (item=[u'ccleaner', u'cura', u'edrawings-viewer', u
'edrawings-viewer-2018', u'malwarebytes', u'uninstalltool', u
'veeam-endpoint-backup-free', u'edrawings-viewer'])
ok: [appserver] => (item=[u'3cx', u'firefox'])

Changing the task that actually removed the package to use 
flatten(levels=1) 

- name: remove old/deprecated packages (choco)
  win_chocolatey:
    name: "{{ item }}"
    state: "absent"
  when:
    - chocolatey_remove_packages is defined
  loop:  "{{ chocolatey_remove_packages|flatten(levels=1) }}"

Givens me the output I've been used to.

Just looking for an explanation on what changed and where I missed this 
change in behavior.

Thanks.

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/9006b3f9-29e6-4163-9265-4623d9732c70%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to