mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
659ef811a3
- 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"
}
]
}
```
(cherry picked from commit
|
||
---|---|---|
.. | ||
fragments | ||
.gitignore | ||
changelog.yaml | ||
config.yaml |