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

Fixes keep_keys filter to retain the entire node when a key match occurs, rather than just the leaf node values. #377

Merged
merged 5 commits into from
Sep 27, 2024

Conversation

roverflow
Copy link
Member

SUMMARY

Fixes keep_keys filter to retain the entire node when a key match occurs, rather than just the leaf node values.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME
  • utils_keep_keys
ADDITIONAL INFORMATION

Playbook to verify

---
- name: Test
  hosts: localhost
  gather_facts: false

  vars:
    tomcat:
      tomcat1:
        name: tomcat1
      tomcat2:
        name: tomcat2
      tomcat3:
        name: asdasd
  tasks:
    - name: keep keys
      ansible.builtin.debug:
        msg: "{{ tomcat | ansible.utils.keep_keys(target=['tomcat1', 'tomcat2']) }}"
    - name: keep keys
      ansible.builtin.debug:
        msg: "{{ tomcat | ansible.utils.remove_keys(target=['tomcat3']) }}"

Output to expect

PLAY [Test] *******************************************************************************************

TASK [keep keys] **************************************************************************************
ok: [localhost] => 
  msg:
    tomcat1:
      name: tomcat1
    tomcat2:
      name: tomcat2

TASK [keep keys] **************************************************************************************
ok: [localhost] => 
  msg:
    tomcat1:
      name: tomcat1
    tomcat2:
      name: tomcat2

Copy link
Contributor

@roverflow roverflow changed the title Bug/keep keys greedy Fixes keep_keys filter to retain the entire node when a key match occurs, rather than just the leaf node values. Sep 26, 2024
Copy link
Contributor

@roverflow roverflow merged commit d902c0f into ansible-collections:main Sep 27, 2024
49 checks passed
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

Successfully merging this pull request may close these issues.

3 participants