Back in May of 2018 I asked “How to use group_vars when managed host is in multiple groups?” (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
`