esolitos

Ansible: Variable in a dictionary key

Jan 24th, 2021 (edited)
692
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 0.72 KB | None | 0 0
  1. ---
  2. ## Expected usage:
  3. -
  4.   name: "{{ website.fancy_name }} - nginx container"
  5.   docker_container:
  6.    ...
  7.     labels:
  8.       "traefik.enable": "true",
  9.       "traefik.http.routers.{{ website.name }}.rule": "Host({{ nginx_traefik_host }})"
  10.  
  11.  
  12.  
  13. ### Actual usage:
  14. -
  15.   name: "{{ website.fancy_name }} - nginx container"
  16.   vars:
  17.    # This hack is needed to allow using a variable in the Dictionary key.
  18.     # @see https://github.com/ansible/ansible/issues/17324#issuecomment-498686519
  19.     container_labels: |
  20.        {
  21.           "traefik.enable": "true",
  22.           "traefik.http.routers.{{ website.name }}.rule": "Host({{ nginx_traefik_host }})"
  23.         }
  24.   docker_container:
  25.    ...
  26.     labels: "{{ container_labels }}"
  27.  
Add Comment
Please, Sign In to add comment