Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community.docker.docker add environment var overwrite #937

Closed
agowa opened this issue Jul 21, 2024 · 5 comments · Fixed by #940
Closed

community.docker.docker add environment var overwrite #937

agowa opened this issue Jul 21, 2024 · 5 comments · Fixed by #940
Labels
docker-plain plain Docker (no swarm, no compose, no stack) enhancement New feature or request

Comments

@agowa
Copy link

agowa commented Jul 21, 2024

SUMMARY

Please add an option to specify environment variables. Sadly lthel existing ansible_docker_extra_args cannot be used to pass the --env option therefore a new additional option would be required.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

community.docker.docker
community.docker.docker_api

ADDITIONAL INFORMATION
- name: GitLab | Add container to inventory
  ansible.builtin.add_host:
    host: '{{ gitlab_container_name }}'
    ansible_connection: docker
    ansible_docker_extra_args: '-H {{ gitlab_dockerhost }}'
    ansible_docker_extra_env:
      PATH: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
    ansible_python_interpreter: '/usr/bin/python3'
    ansible_shell_executable: '/bin/bash'
    ansible_become: false
@felixfontein felixfontein added enhancement New feature or request docker-plain plain Docker (no swarm, no compose, no stack) labels Jul 21, 2024
@felixfontein
Copy link
Collaborator

Sadly lthel existing ansible_docker_extra_args cannot be used to pass the --env option therefore a new additional option would be required.

Out of curiosity: why does that not work?

@agowa
Copy link
Author

agowa commented Jul 22, 2024

@felixfontein because it gets replaced like this: docker $ansible_docker_extra_args exec $containername $command and thereby it ends up before the exec command and the --env needs to be placed after it.

And if you try putting the --env before the exec command anyway you just get a syntax error:

unknown flag: --env
See 'docker --help'.

Usage:  docker [OPTIONS] COMMAND

@felixfontein
Copy link
Collaborator

I've created an implementation in #940. Can you try it out?

@agowa
Copy link
Author

agowa commented Jul 25, 2024

Could you add one or two examples on how to use this new setting from within e.g. an ini file?

You specified it to support ini and env but also it being of type dict.
Until now I wasn't aware that it is possible to specify a dict by an environment variable or within an ini file. I thought it was string, int, bool only.

Is it space separated e.g.:
ansible.cfg:

[docker_connection]
extra_env="foo=bar foobar='bar foo' bar='foo\"bar'"

@felixfontein
Copy link
Collaborator

My guess is that ansible-core's configuratrion manager would accept JSON strings here the same as it would accept them as inputs to dictionary module options. But unfortunately that doesn't seem to be the case, and it only accepts actual mappings :( Well I guess I'll remove env and ini support then, until ansible-core fixes that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docker-plain plain Docker (no swarm, no compose, no stack) enhancement New feature or request
Projects
None yet
2 participants