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

docker_container: fix env_file option #452

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/452-docker_container-env_file.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "docker_container - fix handling of ``env_file`` (https://github.com/ansible-collections/community.docker/issues/451, https://github.com/ansible-collections/community.docker/pull/452)."
2 changes: 2 additions & 0 deletions plugins/module_utils/module_container/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def preprocess(module, values):
return values
self.preprocess = preprocess
self.options = []
self.all_options = []
self.engines = {}
self.ansible_mutually_exclusive = ansible_mutually_exclusive or []
self.ansible_required_together = ansible_required_together or []
Expand All @@ -135,6 +136,7 @@ def add_option(self, *args, **kwargs):
option = Option(*args, owner=self, **kwargs)
if not option.not_a_container_option:
self.options.append(option)
self.all_options.append(option)
if not option.not_an_ansible_option:
ansible_option = {
'type': option.ansible_type,
Expand Down
2 changes: 1 addition & 1 deletion plugins/module_utils/module_container/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def _collect_params(self, active_options):
for options in active_options:
values = {}
engine = options.get_engine(self.engine_driver.name)
for option in options.options:
for option in options.all_options:
if not option.not_an_ansible_option and self.module.params[option.name] is not None:
values[option.name] = self.module.params[option.name]
values = options.preprocess(self.module, values)
Expand Down
51 changes: 51 additions & 0 deletions tests/integration/targets/docker_container/tasks/tests/options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1589,8 +1589,16 @@
- assert:
that:
- env_1 is changed
- "'TEST1=val1' in env_1.container.Config.Env"
- "'TEST2=val2' in env_1.container.Config.Env"
- "'TEST3=False' in env_1.container.Config.Env"
- "'TEST4=true' in env_1.container.Config.Env"
- "'TEST5=yes' in env_1.container.Config.Env"
- env_2 is not changed
- env_3 is not changed
- "'TEST1=val1' in env_4.container.Config.Env"
- "'TEST2=val2' not in env_4.container.Config.Env"
- "'TEST3=val3' in env_4.container.Config.Env"
- env_4 is changed
- env_5 is failed
- "('Non-string value found for env option.') in env_5.msg"
Expand Down Expand Up @@ -1622,6 +1630,41 @@
env_file: "{{ remote_tmp_dir }}/env-file"
register: env_file_2

- name: env_file (with env, idempotent)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
env_file: "{{ remote_tmp_dir }}/env-file"
env:
TEST3: val3
register: env_file_3

- name: env_file (with env)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
env_file: "{{ remote_tmp_dir }}/env-file"
env:
TEST1: val1
TEST3: val3
force_kill: yes
register: env_file_4

- name: env_file (with env, idempotent)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
env_file: "{{ remote_tmp_dir }}/env-file"
env:
TEST1: val1
register: env_file_5

- name: cleanup
docker_container:
name: "{{ cname }}"
Expand All @@ -1632,7 +1675,15 @@
- assert:
that:
- env_file_1 is changed
- "'TEST3=val3' in env_file_1.container.Config.Env"
- "'TEST4=val4' in env_file_1.container.Config.Env"
- env_file_2 is not changed
- env_file_3 is not changed
- env_file_4 is changed
- "'TEST1=val1' in env_file_4.container.Config.Env"
- "'TEST3=val3' in env_file_4.container.Config.Env"
- "'TEST4=val4' in env_file_4.container.Config.Env"
- env_file_5 is not changed

####################################################################
## etc_hosts #######################################################
Expand Down