docker_container env from file

397 views
Skip to first unread message

Emanuele

unread,
May 18, 2020, 9:46:39 AM5/18/20
to Ansible Project
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

Dick Visser

unread,
May 18, 2020, 10:43:43 AM5/18/20
to ansible...@googlegroups.com
Copy the env file to the target first so it _can_ be used?
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/fdafd0db-81fc-494b-9f61-af0247dcb592%40googlegroups.com.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Felix Fontein

unread,
May 18, 2020, 10:48:41 AM5/18/20
to ansible...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages