'ansible playbook to set docker env for inventory file: error passing in dict defined in inventory.yml

In my yaml inventory file, I have this snippet:

 docker_env: {
        "SHOPIFY_PAYMENTS": 1,
        "SHOPIFY_PROMISE_DATES": 1
      }

which defines a dict.

and in my playbook, I have this:

 name: Start django container
  docker_container:
    image: "{{ image_name }}"
    labels: "{{ django_container_labels }}"
...
    env: "{{ docker_env }}"

However, I get this error:

TASK [Start django container] 
fatal: [...growthpath.com.au]: FAILED! => {"changed": false, "msg": "Non-string value found for env option. Ambiguous env options must be wrapped in quotes to avoid them being interpreted. Key: SHOPIFY_PAYMENTS"}

Documentation for env says: "
Dictionary of key,value pairs."

"labels" works; it has the same documentation. This variable is defined in variables.yml, an included file, as:

django_container_labels: {
traefik.http.routers.django-api-router.entrypoints: "web_http,web_https",
....

in other words, I can't see any real difference between docker_env and django_container_labels, except one works and one doesn't.



Solution 1:[1]

ok. THe fix is to do this, quote the value. The error message was more precise than I expected.

 docker_env: {
        "SHOPIFY_PAYMENTS": "1",
        "SHOPIFY_PROMISE_DATES": "1"
      }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tim Richardson