Skip to content

Instantly share code, notes, and snippets.

@fty4
Created July 28, 2020 14:42
Show Gist options
  • Save fty4/88418f6318578b425854bbb66b9c82be to your computer and use it in GitHub Desktop.
Save fty4/88418f6318578b425854bbb66b9c82be to your computer and use it in GitHub Desktop.
convert a ansible list (here docker container info -> Environmentvariables) to a dictionary
- 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