I have this variable :
components:
comp_one:
name: first_component
remote_server_path: "/tmp/path/one"
binaries:
- test
- test_two
comp_two:
name: second_component
remote_server_path: "/tmp/path/two"
binaries:
- ed_test
- ed_test_2
comp_three:
name: third_component
remote_server_path: "/tmp/path/three"
What I'm trying to achieve, is to only keep sub-dictionaries of components that has key binaries, and the filter those binaries using my group_names. Also, D'd like to only keep dict keys binaries and remote_server_path.
For example, if i have this hosts.yaml :
---
all:
children:
kubernetes_dev:
children:
ed_test:
hosts:
host_one:
ansible_host: XXX.XXX.XXX.XXX
ansible_ssh_user: ansible
test_two:
hosts:
host_one:
ansible_host: XXX.XXX.XXX.XXX
ansible_ssh_user: ansible
test:
hosts:
host_one:
ansible_host: XXX.XXX.XXX.XXX
ansible_ssh_user: ansible
The expected output would be :
comp_one:
remote_server_path: "/tmp/path/one"
binaries:
- test
- test_two
comp_two:
remote_server_path: "/tmp/path/two"
binaries:
- ed_test
I've successfully filtered the comp_three dict using this :
- name: Debug
ansible.builtin.debug:
msg: "{{ item }}"
with_items: "{{ components | dict2items | selectattr('value.binaries', 'defined') }}"
But, I can't figure out a way to only select binaries and remote_server_path keys while filtering with my `group_names.
Does anyone can't help me find a clean way to do this ?
Regards,