Created
July 28, 2020 14:42
-
-
Save fty4/88418f6318578b425854bbb66b9c82be to your computer and use it in GitHub Desktop.
convert a ansible list (here docker container info -> Environmentvariables) to a dictionary
This file contains hidden or 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
- name: list2dict | |
hosts: all | |
vars: | |
container_dict: {} | |
tasks: | |
- name: get container info | |
docker_container_info: | |
name: "nginx" | |
register: result | |
- name: convert list to dict | |
set_fact: | |
container_dict: "{{ container_dict | combine({ item.split('=')[0]: item.split('=')[1] }) }}" | |
with_items: "{{ result.container.Config.Env }}" | |
# no_log: true | |
- name: output element | |
debug: | |
msg: "Timezone: {{ container_dict['TZ'] }}; " | |
# msg: "{{ container_dict }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment