Skip to content

Commit

Permalink
docker_container: fix various idempotency problems and non-working op…
Browse files Browse the repository at this point in the history
…tions (#45905)

* Sorting args.

* Doing comparisons of options with container parameters in a more context-sensitive way.

This prevents unnecessary restarts, or missing restarts (f.ex. if parameters are removed from ``cmd``).

* Make blkio_weight work.

* Fix cap_drop idempotency problem.

* Making groups idempotent if it contains integers.

* Make cpuset_mems work.

* Make dns_opts work.

* Fixing log_opts: docker expects string values, returns error for integer.

* Adding tests from felixfontein/ansible-docker_container-test#2.

* Make uts work.

* Adding changelog entry.

* Forgot option security_opts.

* Fixing typo.

* Explain strict set(dict) comparison a bit more.

* Improving idempotency tests.

* Making dns_servers a list, since the ordering is relevant.

* Making dns_search_domains a list, since the ordering is relevant.

* Improving dns_search_domains/dns_servers.

* Fixing entrypoint test.

* Making sure options are only supported for correct docker-py versions.
  • Loading branch information
felixfontein authored and abadger committed Oct 10, 2018
1 parent 18b575b commit 1d01543
Show file tree
Hide file tree
Showing 7 changed files with 3,498 additions and 113 deletions.
7 changes: 7 additions & 0 deletions changelogs/fragments/docker_container-idempotency.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bugfixes:
- "docker_container - Makes ``blkio_weight``, ``cpuset_mems``, ``dns_opts`` and ``uts`` options actually work."
- "docker_container - Fix idempotency problems with ``cap_drop`` and ``groups`` (when numeric group IDs were used)."
- "docker_container - Fix type conversion errors for ``log_options``."
- "docker_container - Fixing various comparison/idempotency problems related to wrong comparisons.
In particular, comparisons for ``command`` and ``entrypoint`` (both lists) no longer ignore missing
elements during idempotency checks."
288 changes: 206 additions & 82 deletions lib/ansible/modules/cloud/docker/docker_container.py

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions test/integration/targets/docker_container/files/env-file
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TEST3=val3
TEST4=val4
46 changes: 27 additions & 19 deletions test/integration/targets/docker_container/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
---
- block:
- name: Create random container name prefix
set_fact:
cname_prefix: "{{ 'ansible-test-%0x' % ((2**32) | random) }}"
cnames: []
- name: Create random container name prefix
set_fact:
cname_prefix: "{{ 'ansible-test-%0x' % ((2**32) | random) }}"
cnames: []
dnetworks: []

- debug:
msg: "Using container name prefix {{ cname_prefix }}"

- debug:
msg: "Using container name prefix {{ cname_prefix }}"
- block:
- include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"

- block:
- include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"
always:
- name: "Make sure all containers are removed"
docker_container:
name: "{{ item }}"
state: absent
stop_timeout: 1
with_items: "{{ cnames }}"
- name: "Make sure all networks are removed"
docker_network:
name: "{{ item }}"
state: absent
force: yes
with_items: "{{ dnetworks }}"

always:
- name: "Make sure all containers are removed"
docker_container:
name: "{{ item }}"
state: absent
stop_timeout: 1
with_items: "{{ cnames }}"
when: ansible_os_family != 'RedHat' or ansible_distribution_major_version != '6'
# Skip for CentOS 6
when: ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6

0 comments on commit 1d01543

Please sign in to comment.