docker_container env from file

Hi,

i’m trying to pass environment variables to my docker with env and populate it with a file. Like this:

`

  • name: deploy container

docker_container:
name: test
image: debian
env:
include_vars:
file: workbench.yml
`

i can’t use env_file because the file isn’t present to target host and i’m searching a workaround but when i execute this i got:

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: include_vars"}

there is a way to populate env from a file?

Thanks a lot

Copy the env file to the target first so it _can_ be used?

Hi,

i'm trying to pass environment variables to my docker with *env *and
populate it with a file. Like this:

- name: deploy container

      docker_container:
        name: test
        image: debian
        env:
          include_vars:
            file: workbench.yml

instead of randomly combining Ansible constructs, use Jinja2. Something
like this should work:

        env: "{{ lookup('file', 'workbench.yml') | from_yaml }}"

https://docs.ansible.com/ansible/latest/plugins/lookup/file.html
https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#filters-for-formatting-data

Cheers,
Felix