docker_container: fix various idempotency problems and non-working options (#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.
This commit is contained in:
Felix Fontein 2018-09-24 11:40:05 +02:00 committed by John R Barker
parent 0b801a0595
commit 7caf70db42
7 changed files with 3499 additions and 114 deletions

View file

@ -0,0 +1,2 @@
TEST3=val3
TEST4=val4

View file

@ -1,23 +1,31 @@
---
- 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 }}"
- block:
- name: Create random container name prefix
set_fact:
cname_prefix: "{{ 'ansible-test-%0x' % ((2**32) | random) }}"
cnames: []
- include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"
- debug:
msg: "Using container name prefix {{ cname_prefix }}"
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 }}"
- 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 }}"
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

File diff suppressed because it is too large Load diff

View file

@ -10,7 +10,7 @@
- name: Start container
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 1h"'
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started

View file

@ -13,7 +13,7 @@
- name: Create container (check)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 1h"'
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: present
check_mode: yes
@ -22,7 +22,7 @@
- name: Create container
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 1h"'
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: present
register: create_2
@ -30,7 +30,7 @@
- name: Create container (idempotent)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 1h"'
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: present
register: create_3
@ -38,7 +38,7 @@
- name: Create container (idempotent check)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 1h"'
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: present
check_mode: yes
@ -95,7 +95,7 @@
- name: Present check for running container (check)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 1h"'
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: present
check_mode: yes
@ -104,7 +104,7 @@
- name: Present check for running container
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 1h"'
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: present
register: present_check_2
@ -127,7 +127,7 @@
- name: Start container from scratch (check)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 1h"'
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
check_mode: yes
@ -136,7 +136,7 @@
- name: Start container from scratch
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 1h"'
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
register: start_scratch_2
@ -144,7 +144,7 @@
- name: Start container from scratch (idempotent)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 1h"'
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
register: start_scratch_3
@ -152,7 +152,7 @@
- name: Start container from scratch (idempotent check)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 1h"'
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
check_mode: yes
@ -254,7 +254,7 @@
- name: Start container (setup for removing from running)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 1h"'
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started