Open vbotka opened 6 months ago
The function ansible.utils.keep_keys doesn't exclude a key if the value is a list.
ansible.utils.keep_keys
ansible [core 2.16.6] config file = /export/scratch/sandbox/tmp1/test-15/ansible.cfg configured module search path = ['/home/vlado/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /home/vlado/env/lib/python3.12/site-packages/ansible ansible collection location = /home/vlado/.ansible/collections:/usr/share/ansible/collections executable location = /home/vlado/env/bin/ansible python version = 3.12.3 (main, Apr 10 2024, 05:33:47) [GCC 13.2.0] (/home/vlado/env/bin/python) jinja version = 3.1.4 libyaml = True
# /home/vlado/env/lib/python3.12/site-packages/ansible_collections Collection Version ------------- ------- ansible.utils 2.12.0
CONFIG_FILE() = /export/scratch/sandbox/tmp1/test-15/ansible.cfg DEFAULT_GATHERING(/export/scratch/sandbox/tmp1/test-15/ansible.cfg) = explicit DEFAULT_HOST_LIST(/export/scratch/sandbox/tmp1/test-15/ansible.cfg) = ['/export/scratch/sandbox/tmp1/test-15/hosts'] DEFAULT_LOG_PATH(/export/scratch/sandbox/tmp1/test-15/ansible.cfg) = /var/log/ansible.log DEFAULT_STDOUT_CALLBACK(/export/scratch/sandbox/tmp1/test-15/ansible.cfg) = yaml EDITOR(env: EDITOR) = emacs PAGER(env: PAGER) = /usr/bin/most -s
DISTRIB_ID=Ubuntu DISTRIB_RELEASE=24.04 DISTRIB_CODENAME=noble DISTRIB_DESCRIPTION="Ubuntu 24.04 LTS"
- hosts: localhost vars: t: [k0, k1] l1: - {k0: A, k1: B, k2: [1], k3: foo} - {k0: A, k1: B, k2: [2], k3: bar} r1: "{{ l1 | ansible.utils.keep_keys(target=t) }}" l2: - {k0: A, k1: B, k2: C, k3: foo} - {k0: A, k1: B, k2: C, k3: bar} r2: "{{ l2 | ansible.utils.keep_keys(target=t) }}" tasks: - debug: var: r1 - debug: var: r2
gives (abridged)
r1: - k0: A k1: B k2: - 1 - k0: A k1: B k2: - 2 r2: - k0: A k1: B - k0: A k1: B
r1: - k0: A k1: B - k0: A k1: B
r1: - k0: A k1: B k2: - 1 - k0: A k1: B k2: - 2
It should be fixed by https://github.com/ansible-collections/ansible.utils/pull/379
SUMMARY
The function ansible.utils.keep_keys doesn't exclude a key if the value is a list.
ISSUE TYPE
COMPONENT NAME
ansible.utils.keep_keys
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
STEPS TO REPRODUCE
gives (abridged)
EXPECTED RESULTS
ACTUAL RESULTS