mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-27 10:40:22 -07:00
Add filter dict_kv (#1264)
- Add filter `dict_kv` which returns a single key-value pair dictionary created from two arguments Example 1 ``` - hosts: localhost gather_facts: false vars: myvar: myvalue tasks: - debug: msg: "{{ myvar | dict_kv('thatsmyvar') }}" OUTPUT: ok: [localhost] => { "msg": { "thatsmyvar": "myvalue" } } ``` Example 2 ``` - hosts: localhost gather_facts: false vars: common_config: type: host database: all myservers: - server1 - server2 tasks: - debug: msg: "{{ myservers | map('dict_kv', 'server') | map('combine', common_config) }}" OUTPUT: ok: [localhost] => { "msg": [ { "database": "all", "server": "server1", "type": "host" }, { "database": "all", "server": "server2", "type": "host" } ] } ```
This commit is contained in:
parent
ce5fc7764a
commit
44fd157a2b
4 changed files with 84 additions and 0 deletions
2
tests/integration/targets/filter_dict_kv/aliases
Normal file
2
tests/integration/targets/filter_dict_kv/aliases
Normal file
|
@ -0,0 +1,2 @@
|
|||
shippable/posix/group2
|
||||
skip/python2.6 # filters are controller only, and we no longer support Python 2.6 on the controller
|
10
tests/integration/targets/filter_dict_kv/tasks/main.yml
Normal file
10
tests/integration/targets/filter_dict_kv/tasks/main.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
####################################################################
|
||||
# WARNING: These are designed specifically for Ansible tests #
|
||||
# and should not be used as examples of how to write Ansible roles #
|
||||
####################################################################
|
||||
|
||||
- name: test dict_kv filter
|
||||
assert:
|
||||
that:
|
||||
- "('value' | community.general.dict_kv('key')) == {'key': 'value'}"
|
Loading…
Add table
Add a link
Reference in a new issue