Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keep_keys doesn't exclude a key if the value is list. #353

Open
vbotka opened this issue May 29, 2024 · 0 comments
Open

keep_keys doesn't exclude a key if the value is list. #353

vbotka opened this issue May 29, 2024 · 0 comments
Assignees

Comments

@vbotka
Copy link
Contributor

vbotka commented May 29, 2024

SUMMARY

The function ansible.utils.keep_keys doesn't exclude a key if the value is a list.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

ansible.utils.keep_keys

ANSIBLE VERSION
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
COLLECTION VERSION
# /home/vlado/env/lib/python3.12/site-packages/ansible_collections
Collection    Version
------------- -------
ansible.utils 2.12.0
CONFIGURATION
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
OS / ENVIRONMENT
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=24.04
DISTRIB_CODENAME=noble
DISTRIB_DESCRIPTION="Ubuntu 24.04 LTS"
STEPS TO REPRODUCE
- 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
EXPECTED RESULTS
  r1:
  - k0: A
    k1: B
  - k0: A
    k1: B
ACTUAL RESULTS
  r1:
  - k0: A
    k1: B
    k2:
    - 1
  - k0: A
    k1: B
    k2:
    - 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants