ansible-collections / ansible.utils

A collection of ansible utilities for the content creator.
GNU General Public License v3.0
74 stars 76 forks source link

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

Closed roverflow closed 5 days ago

roverflow commented 6 days ago
SUMMARY

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

ISSUE TYPE
COMPONENT NAME
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
softwarefactory-project-zuul[bot] commented 6 days ago

Build succeeded. https://ansible.softwarefactory-project.io/zuul/buildset/be02bd0ac1fa4d21a4d686a56981d181

:heavy_check_mark: ansible-galaxy-importer SUCCESS in 3m 31s :heavy_check_mark: build-ansible-collection SUCCESS in 5m 46s

softwarefactory-project-zuul[bot] commented 5 days ago

Build succeeded. https://ansible.softwarefactory-project.io/zuul/buildset/9244408110c8469cbc5950ac62be814e

:heavy_check_mark: ansible-galaxy-importer SUCCESS in 4m 45s :heavy_check_mark: build-ansible-collection SUCCESS in 5m 50s