# docker\_container env from file

**URL:** <https://forum.ansible.com/t/docker-container-env-from-file/32888>\
**Category:** Ansible Project\
**Created:** [May 8, 2020, 4:36pm UTC](https://forum.ansible.com/t/docker-container-env-from-file/32888 "2020-05-08T16:36:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emanuele](https://avatars.discourse-cdn.com/v4/letter/e/e0b2c6/32.png) [@Emanuele](https://forum.ansible.com/u/Emanuele)\
**Post date:** [May 8, 2020, 4:36pm UTC](https://forum.ansible.com/t/docker-container-env-from-file/32888/1 "2020-05-08T16:36:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [May 18, 2020, 2:43pm UTC](https://forum.ansible.com/t/docker-container-env-from-file/32888/2 "2020-05-18T14:43:12Z")

</div>

Copy the env file to the target first so it \_can\_ be used?

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [May 18, 2020, 2:48pm UTC](https://forum.ansible.com/t/docker-container-env-from-file/32888/3 "2020-05-18T14:48:19Z")

</div>

Hi,

> i'm trying to pass environment variables to my docker with \*env \*and  
> populate it with a file. Like this:
> 
> - name: deploy container
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;docker\_container:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: test  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;image: debian  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;env:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include\_vars:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file: workbench.yml

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

> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;env: "{{ lookup('file', 'workbench.yml') | from\_yaml }}"

[https://docs.ansible.com/ansible/latest/plugins/lookup/file.html](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](https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#filters-for-formatting-data)

Cheers,  
Felix
