Last active
March 17, 2022 16:36
-
-
Save kcem/5ec90b97c08fafd0397f248e8c31b25b to your computer and use it in GitHub Desktop.
Create, modify, refill dictionary in Ansible based on other variables. Way of Ansible rename dictionary keys.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: all | |
gather_facts: false | |
vars: | |
data_source: | |
- {src_host: 172.16.0.10, src_user: www-data, dst_host: 172.16.0.11, dst_user: mysql} | |
- {src_host: 172.16.0.10, src_user: ftp, dst_host: 172.16.0.11, dst_user: mysql} | |
- {src_host: 172.16.0.10, src_user: ftp, dst_host: 172.16.0.12, dst_user: nat} | |
- {src_host: 172.16.0.10, src_user: www-data, dst_host: 172.16.0.14, dst_user: mysql} | |
list_of_users: | |
"{{ data_source|map(attribute='src_user')|union(data_source|map(attribute='dst_user'))|unique }}" | |
list_of_users_pairs_yml: |- | |
{% for item in data_source %} | |
- src: {{ item.src_user }} | |
dst: {{ item.dst_user }} | |
opt: {{ item.optional_value|d('') }} | |
{% endfor %} | |
list_of_users_pairs: "{{ list_of_users_pairs_yml|from_yaml|unique }}" | |
tasks: | |
- debug: var=list_of_users | |
- debug: var=list_of_users_pairs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment