Use FQCNs. (#1180)

This commit is contained in:
Felix Fontein 2025-10-25 10:12:21 +02:00 committed by GitHub
parent be000755fc
commit b24bce77b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
196 changed files with 3289 additions and 3289 deletions

View File

@ -8,13 +8,13 @@
docker_test_image_alpine: quay.io/ansible/docker-test-containers:alpine3.8
tasks:
- name: Find all roles
find:
ansible.builtin.find:
paths:
- "{{ (playbook_dir | default('.')) ~ '/roles' }}"
file_type: directory
depth: 1
register: result
- name: Include all roles
include_role:
ansible.builtin.include_role:
name: "{{ item }}"
loop: "{{ result.files | map(attribute='path') | map('regex_replace', '.*/', '') | sort }}"

View File

@ -10,11 +10,11 @@
# The following two tasks are useful if we ever have to debug why this fails.
- name: Print all Ansible facts
debug:
ansible.builtin.debug:
var: ansible_facts
- name: Read some files
slurp:
ansible.builtin.slurp:
src: "{{ path }}"
loop:
- /proc/self/cpuset
@ -24,11 +24,11 @@
loop_var: path
- name: Print facts returned by module
debug:
ansible.builtin.debug:
var: result.ansible_facts
- name: Validate results
assert:
ansible.builtin.assert:
that:
- ansible_module_running_in_container
- ansible_module_container_type != ''

View File

@ -5,7 +5,7 @@
# Create random name prefix (for containers, networks, ...)
- name: Create random container name prefix
set_fact:
ansible.builtin.set_fact:
cname_prefix: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
- name: Make sure image is absent

View File

@ -9,7 +9,7 @@
####################################################################
- name: Get facts
current_container_facts:
community.docker.current_container_facts:
register: result
# WARNING: This is not a proper test as it won't fail when the module does not work!

View File

@ -10,21 +10,21 @@
# Create random name prefix (for services, ...)
- name: Create random container name prefix
set_fact:
ansible.builtin.set_fact:
name_prefix: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
cnames: []
dnetworks: []
images: []
- debug:
- ansible.builtin.debug:
msg: "Using name prefix {{ name_prefix }}"
# Run the tests
- block:
- name: Show docker compose --help output
command: docker compose --help
ansible.builtin.command: docker compose --help
- include_tasks: run-test.yml
- ansible.builtin.include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"
loop_control:
@ -32,7 +32,7 @@
always:
- name: "Make sure all containers are removed"
docker_container:
community.docker.docker_container:
name: "{{ item }}"
state: absent
force_kill: true
@ -40,7 +40,7 @@
diff: false
- name: "Make sure all networks are removed"
docker_network:
community.docker.docker_network:
name: "{{ item }}"
state: absent
force: true
@ -48,7 +48,7 @@
diff: false
- name: "Make sure all images are removed"
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ item }}"
loop: "{{ images }}"
diff: false

View File

@ -4,4 +4,4 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: "Loading tasks from {{ test_name }}"
include_tasks: "{{ test_name }}"
ansible.builtin.include_tasks: "{{ test_name }}"

View File

@ -18,13 +18,13 @@
block:
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cnames: "{{ cnames + [pname ~ '-' ~ cname ~ '-1'] }}"
dnetworks: "{{ dnetworks + [pname ~ '_default'] }}"
images: "{{ images + [iname] }}"
- name: Create project directory
file:
ansible.builtin.file:
path: '{{ item }}'
state: directory
loop:
@ -32,45 +32,45 @@
- '{{ project_src }}/build'
- name: Template default project file
copy:
ansible.builtin.copy:
dest: '{{ project_src }}/docker-compose.yml'
content: '{{ test_service }}'
- name: Template Dockerfile
copy:
ansible.builtin.copy:
dest: '{{ project_src }}/build/Dockerfile'
content: |
FROM {{ docker_test_image_alpine }}
ENTRYPOINT ["/bin/sh", "-c", "sleep 10m"]
- name: Present (check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
check_mode: true
register: present_1_check
- name: Present
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
register: present_1
- name: Present (idempotent check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
check_mode: true
register: present_2_check
- name: Present (idempotent)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
register: present_2
- name: Present (idempotent check, build=always, ignore_build_events=false)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
build: always
@ -79,7 +79,7 @@
register: present_3_check
- name: Present (idempotent, build=always, ignore_build_events=false)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
build: always
@ -87,7 +87,7 @@
register: present_3
- name: Present (idempotent check, build=always, ignore_build_events=true)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
build: always
@ -96,14 +96,14 @@
register: present_4_check
- name: Present (idempotent, build=always, ignore_build_events=true)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
build: always
ignore_build_events: true
register: present_4
- assert:
- ansible.builtin.assert:
that:
- present_1_check is changed
- present_1_check.warnings | default([]) | select('regex', ' please report this at ') | length == 0
@ -135,6 +135,6 @@
always:
- name: Cleanup
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: absent

View File

@ -16,22 +16,22 @@
block:
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cnames: "{{ cnames + [pname ~ '-' ~ cname ~ '-1'] }}"
dnetworks: "{{ dnetworks + [pname ~ '_default'] }}"
- name: Create project directory
file:
ansible.builtin.file:
path: '{{ project_src }}'
state: directory
- name: Template default project file
copy:
ansible.builtin.copy:
dest: '{{ project_src }}/docker-compose.yml'
content: '{{ test_service }}'
- name: Present (check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
wait: true
@ -39,7 +39,7 @@
register: present_1_check
- name: Present
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
wait: true
@ -47,11 +47,11 @@
ignore_errors: true
- name: Cleanup
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: absent
- assert:
- ansible.builtin.assert:
that:
- present_1_check is changed
- present_1_check.warnings | default([]) | select('regex', ' please report this at ') | length == 0

View File

@ -21,7 +21,7 @@
block:
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cnames: "{{ cnames + [pname ~ '-' ~ cname ~ '-1'] }}"
dnetworks: "{{ dnetworks + [pname ~ '_default'] }}"
@ -30,7 +30,7 @@
####################################################################
- name: Present (check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_name: '{{ pname }}'
definition: '{{ test_service | from_yaml }}'
state: present
@ -38,14 +38,14 @@
register: present_1_check
- name: Present
docker_compose_v2:
community.docker.docker_compose_v2:
project_name: '{{ pname }}'
definition: '{{ test_service | from_yaml }}'
state: present
register: present_1
- name: Present (idempotent check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_name: '{{ pname }}'
definition: '{{ test_service | from_yaml }}'
state: present
@ -53,14 +53,14 @@
register: present_2_check
- name: Present (idempotent)
docker_compose_v2:
community.docker.docker_compose_v2:
project_name: '{{ pname }}'
definition: '{{ test_service | from_yaml }}'
state: present
register: present_2
- name: Present (changed check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_name: '{{ pname }}'
definition: '{{ test_service_mod | from_yaml }}'
state: present
@ -68,13 +68,13 @@
register: present_3_check
- name: Present (changed)
docker_compose_v2:
community.docker.docker_compose_v2:
project_name: '{{ pname }}'
definition: '{{ test_service_mod | from_yaml }}'
state: present
register: present_3
- assert:
- ansible.builtin.assert:
that:
- present_1_check is changed
- present_1_check.warnings | default([]) | select('regex', ' please report this at ') | length == 0
@ -103,7 +103,7 @@
####################################################################
- name: Absent (check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_name: '{{ pname }}'
definition: '{{ test_service_mod | from_yaml }}'
state: absent
@ -111,14 +111,14 @@
register: absent_1_check
- name: Absent
docker_compose_v2:
community.docker.docker_compose_v2:
project_name: '{{ pname }}'
definition: '{{ test_service_mod | from_yaml }}'
state: absent
register: absent_1
- name: Absent (idempotent check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_name: '{{ pname }}'
definition: '{{ test_service_mod | from_yaml }}'
state: absent
@ -126,13 +126,13 @@
register: absent_2_check
- name: Absent (idempotent)
docker_compose_v2:
community.docker.docker_compose_v2:
project_name: '{{ pname }}'
definition: '{{ test_service_mod | from_yaml }}'
state: absent
register: absent_2
- assert:
- ansible.builtin.assert:
that:
- absent_1_check is changed
- absent_1_check.warnings | default([]) | select('regex', ' please report this at ') | length == 0
@ -148,7 +148,7 @@
####################################################################
- name: Present stopped (check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_name: '{{ pname }}'
definition: '{{ test_service | from_yaml }}'
state: stopped
@ -156,14 +156,14 @@
register: present_1_check
- name: Present stopped
docker_compose_v2:
community.docker.docker_compose_v2:
project_name: '{{ pname }}'
definition: '{{ test_service | from_yaml }}'
state: stopped
register: present_1
- name: Present stopped (idempotent check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_name: '{{ pname }}'
definition: '{{ test_service | from_yaml }}'
state: stopped
@ -171,14 +171,14 @@
register: present_2_check
- name: Present stopped (idempotent)
docker_compose_v2:
community.docker.docker_compose_v2:
project_name: '{{ pname }}'
definition: '{{ test_service | from_yaml }}'
state: stopped
register: present_2
- name: Started (check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_name: '{{ pname }}'
definition: '{{ test_service | from_yaml }}'
state: present
@ -186,14 +186,14 @@
register: present_3_check
- name: Started
docker_compose_v2:
community.docker.docker_compose_v2:
project_name: '{{ pname }}'
definition: '{{ test_service | from_yaml }}'
state: present
register: present_3
- name: Started (idempotent check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_name: '{{ pname }}'
definition: '{{ test_service | from_yaml }}'
state: present
@ -201,14 +201,14 @@
register: present_4_check
- name: Started (idempotent)
docker_compose_v2:
community.docker.docker_compose_v2:
project_name: '{{ pname }}'
definition: '{{ test_service | from_yaml }}'
state: present
register: present_4
- name: Restarted (check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_name: '{{ pname }}'
definition: '{{ test_service | from_yaml }}'
state: restarted
@ -216,14 +216,14 @@
register: present_5_check
- name: Restarted
docker_compose_v2:
community.docker.docker_compose_v2:
project_name: '{{ pname }}'
definition: '{{ test_service | from_yaml }}'
state: restarted
register: present_5
- name: Stopped (check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_name: '{{ pname }}'
definition: '{{ test_service | from_yaml }}'
state: stopped
@ -231,14 +231,14 @@
register: present_6_check
- name: Stopped
docker_compose_v2:
community.docker.docker_compose_v2:
project_name: '{{ pname }}'
definition: '{{ test_service | from_yaml }}'
state: stopped
register: present_6
- name: Restarted (check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_name: '{{ pname }}'
definition: '{{ test_service | from_yaml }}'
state: restarted
@ -246,19 +246,19 @@
register: present_7_check
- name: Restarted
docker_compose_v2:
community.docker.docker_compose_v2:
project_name: '{{ pname }}'
definition: '{{ test_service | from_yaml }}'
state: restarted
register: present_7
- name: Cleanup
docker_compose_v2:
community.docker.docker_compose_v2:
project_name: '{{ pname }}'
definition: '{{ test_service | from_yaml }}'
state: absent
- assert:
- ansible.builtin.assert:
that:
- present_1_check is changed
- present_1_check.warnings | default([]) | select('regex', ' please report this at ') | length == 0

View File

@ -21,17 +21,17 @@
block:
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cnames: "{{ cnames + [pname ~ '-' ~ cname ~ '-1'] }}"
dnetworks: "{{ dnetworks + [pname ~ '_default'] }}"
- name: Create project directory
file:
ansible.builtin.file:
path: '{{ project_src }}'
state: directory
- name: Make sure images are not around
docker_image_remove:
community.docker.docker_image_remove:
name: '{{ item }}'
loop:
- '{{ non_existing_image }}'
@ -42,12 +42,12 @@
####################################################################
- name: Template project file with non-existing image
copy:
ansible.builtin.copy:
dest: '{{ project_src }}/docker-compose.yml'
content: '{{ test_service_non_existing }}'
- name: Present with pull=never (check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
pull: never
@ -56,7 +56,7 @@
ignore_errors: true
- name: Present with pull=never
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
pull: never
@ -64,7 +64,7 @@
ignore_errors: true
- name: Present without explicit pull (check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
check_mode: true
@ -72,13 +72,13 @@
ignore_errors: true
- name: Present without explicit pull
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
register: present_2
ignore_errors: true
- assert:
- ansible.builtin.assert:
that:
- present_1_check is failed or present_1_check is changed
- present_1_check is changed or present_1_check.msg.startswith('General error:')
@ -98,12 +98,12 @@
####################################################################
- name: Template project file with simple image
copy:
ansible.builtin.copy:
dest: '{{ project_src }}/docker-compose.yml'
content: '{{ test_service_simple }}'
- name: Present with pull=missing (check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
pull: missing
@ -111,14 +111,14 @@
register: present_1_check
- name: Present with pull=missing
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
pull: missing
register: present_1
- name: Present with pull=missing (idempotent, check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
pull: missing
@ -126,14 +126,14 @@
register: present_2_check
- name: Present with pull=missing (idempotent)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
pull: missing
register: present_2
- name: Present with pull=always (check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
pull: always
@ -141,19 +141,19 @@
register: present_3_check
- name: Present with pull=always
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
pull: always
register: present_3
- name: Stopping service
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: absent
- name: Present with pull=never (check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
pull: missing
@ -161,14 +161,14 @@
register: present_4_check
- name: Present with pull=never
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
pull: missing
register: present_4
- name: Present with pull=never (idempotent, check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
pull: missing
@ -176,18 +176,18 @@
register: present_5_check
- name: Present with pull=never (idempotent)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
pull: missing
register: present_5
- name: Cleanup
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: absent
- assert:
- ansible.builtin.assert:
that:
- present_1_check is changed
- (present_1_check.actions | selectattr('status', 'eq', 'Pulling') | first) is truthy

View File

@ -22,12 +22,12 @@
block:
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cnames: "{{ cnames + [pname ~ '-' ~ cname ~ '-1'] }}"
dnetworks: "{{ dnetworks + [pname ~ '_default'] }}"
- name: Create project directory
file:
ansible.builtin.file:
path: '{{ project_src }}'
state: directory
@ -36,62 +36,62 @@
####################################################################
- name: Template default project file
copy:
ansible.builtin.copy:
dest: '{{ project_src }}/docker-compose.yml'
content: '{{ test_service }}'
- name: Present (check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
check_mode: true
register: present_1_check
- name: Present
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
register: present_1
- name: Present (idempotent check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
check_mode: true
register: present_2_check
- name: Present (idempotent)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
register: present_2
- name: Template modified project file
copy:
ansible.builtin.copy:
dest: '{{ project_src }}/docker-compose.yml'
content: '{{ test_service_mod }}'
- name: Present (changed check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
check_mode: true
register: present_3_check
- name: Present (changed)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
register: present_3
- name: Present with --yes
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
assume_yes: true
when: docker_compose_version is version('2.32.0', '>=')
- assert:
- ansible.builtin.assert:
that:
- present_1_check is changed
- present_1_check.warnings | default([]) | select('regex', ' please report this at ') | length == 0
@ -120,32 +120,32 @@
####################################################################
- name: Absent (check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: absent
check_mode: true
register: absent_1_check
- name: Absent
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: absent
register: absent_1
- name: Absent (idempotent check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: absent
check_mode: true
register: absent_2_check
- name: Absent (idempotent)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: absent
register: absent_2
- assert:
- ansible.builtin.assert:
that:
- absent_1_check is changed
- absent_1_check.warnings | default([]) | select('regex', ' please report this at ') | length == 0
@ -161,107 +161,107 @@
####################################################################
- name: Template default project file
copy:
ansible.builtin.copy:
dest: '{{ project_src }}/docker-compose.yml'
content: '{{ test_service }}'
- name: Present stopped (check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: stopped
check_mode: true
register: present_1_check
- name: Present stopped
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: stopped
register: present_1
- name: Present stopped (idempotent check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: stopped
check_mode: true
register: present_2_check
- name: Present stopped (idempotent)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: stopped
register: present_2
- name: Started (check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
check_mode: true
register: present_3_check
- name: Started
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
register: present_3
- name: Started (idempotent check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
check_mode: true
register: present_4_check
- name: Started (idempotent)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
register: present_4
- name: Restarted (check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: restarted
check_mode: true
register: present_5_check
- name: Restarted
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: restarted
register: present_5
- name: Stopped (check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: stopped
check_mode: true
register: present_6_check
- name: Stopped
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: stopped
register: present_6
- name: Restarted (check)
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: restarted
check_mode: true
register: present_7_check
- name: Restarted
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: restarted
register: present_7
- name: Cleanup
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: absent
- assert:
- ansible.builtin.assert:
that:
- present_1_check is changed
- present_1_check.warnings | default([]) | select('regex', ' please report this at ') | length == 0

View File

@ -10,20 +10,20 @@
# Create random name prefix (for services, ...)
- name: Create random container name prefix
set_fact:
ansible.builtin.set_fact:
name_prefix: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
cnames: []
dnetworks: []
- debug:
- ansible.builtin.debug:
msg: "Using name prefix {{ name_prefix }}"
# Run the tests
- block:
- name: Show docker compose --help output
command: docker compose --help
ansible.builtin.command: docker compose --help
- include_tasks: run-test.yml
- ansible.builtin.include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"
loop_control:
@ -31,7 +31,7 @@
always:
- name: "Make sure all containers are removed"
docker_container:
community.docker.docker_container:
name: "{{ item }}"
state: absent
force_kill: true
@ -39,7 +39,7 @@
diff: false
- name: "Make sure all networks are removed"
docker_network:
community.docker.docker_network:
name: "{{ item }}"
state: absent
force: true

View File

@ -4,4 +4,4 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: "Loading tasks from {{ test_name }}"
include_tasks: "{{ test_name }}"
ansible.builtin.include_tasks: "{{ test_name }}"

View File

@ -16,35 +16,35 @@
block:
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cnames: "{{ cnames + [pname ~ '-' ~ cname ~ '-1'] }}"
dnetworks: "{{ dnetworks + [pname ~ '_default'] }}"
- name: Create project directory
file:
ansible.builtin.file:
path: '{{ project_src }}'
state: directory
- name: Template default project file
copy:
ansible.builtin.copy:
dest: '{{ project_src }}/docker-compose.yml'
content: '{{ test_service }}'
- block:
- name: Start services
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
- name: Run command with command
docker_compose_v2_exec:
community.docker.docker_compose_v2_exec:
project_src: '{{ project_src }}'
service: '{{ cname }}'
command: /bin/sh -c "ls /"
register: result_1
- name: Run command with argv
docker_compose_v2_exec:
community.docker.docker_compose_v2_exec:
project_src: '{{ project_src }}'
service: '{{ cname }}'
argv:
@ -56,7 +56,7 @@
failed_when: result_2.rc != 1
- name: Run detached command
docker_compose_v2_exec:
community.docker.docker_compose_v2_exec:
project_src: '{{ project_src }}'
service: '{{ cname }}'
command: /bin/sh -c "sleep 1"
@ -64,14 +64,14 @@
register: result_3
- name: Run command with input
docker_compose_v2_exec:
community.docker.docker_compose_v2_exec:
project_src: '{{ project_src }}'
service: '{{ cname }}'
command: /bin/sh -c "cat"
stdin: This is a test
register: result_4
- assert:
- ansible.builtin.assert:
that:
- result_1.rc == 0
- result_1.stderr == ""
@ -92,6 +92,6 @@
always:
- name: Cleanup
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: absent

View File

@ -10,23 +10,23 @@
# Create random name prefix (for services, ...)
- name: Create random container name prefix
set_fact:
ansible.builtin.set_fact:
name_prefix: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
cnames: []
dnetworks: []
- debug:
- ansible.builtin.debug:
msg: "Using name prefix {{ name_prefix }}"
- name: Show images
command: docker images --all --digests
ansible.builtin.command: docker images --all --digests
# Run the tests
- block:
- name: Show docker compose --help output
command: docker compose --help
ansible.builtin.command: docker compose --help
- include_tasks: run-test.yml
- ansible.builtin.include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"
loop_control:
@ -34,7 +34,7 @@
always:
- name: "Make sure all containers are removed"
docker_container:
community.docker.docker_container:
name: "{{ item }}"
state: absent
force_kill: true
@ -42,7 +42,7 @@
diff: false
- name: "Make sure all networks are removed"
docker_network:
community.docker.docker_network:
name: "{{ item }}"
state: absent
force: true

View File

@ -4,4 +4,4 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: "Loading tasks from {{ test_name }}"
include_tasks: "{{ test_name }}"
ansible.builtin.include_tasks: "{{ test_name }}"

View File

@ -23,17 +23,17 @@
block:
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cnames: "{{ cnames + [pname ~ '-' ~ cname ~ '-1'] }}"
dnetworks: "{{ dnetworks + [pname ~ '_default'] }}"
- name: Create project directory
file:
ansible.builtin.file:
path: '{{ project_src }}'
state: directory
- name: Make sure images are not around
docker_image_remove:
community.docker.docker_image_remove:
name: '{{ item }}'
loop:
- '{{ non_existing_image }}'
@ -44,24 +44,24 @@
####################################################################
- name: Template project file with non-existing image
copy:
ansible.builtin.copy:
dest: '{{ project_src }}/docker-compose.yml'
content: '{{ test_service_non_existing }}'
- name: Pull (check)
docker_compose_v2_pull:
community.docker.docker_compose_v2_pull:
project_src: '{{ project_src }}'
check_mode: true
register: pull_1_check
ignore_errors: true
- name: Pull
docker_compose_v2_pull:
community.docker.docker_compose_v2_pull:
project_src: '{{ project_src }}'
register: pull_1
ignore_errors: true
- assert:
- ansible.builtin.assert:
that:
- pull_1_check is failed or pull_1_check is changed
- pull_1_check is changed or pull_1_check.msg.startswith('Error when processing ')
@ -75,69 +75,69 @@
####################################################################
- name: Template project file with simple image
copy:
ansible.builtin.copy:
dest: '{{ project_src }}/docker-compose.yml'
content: '{{ test_service_simple }}'
- when: docker_compose_version is version('2.22.0', '>=')
block:
- name: Pull with policy=missing (check)
docker_compose_v2_pull:
community.docker.docker_compose_v2_pull:
project_src: '{{ project_src }}'
policy: missing
check_mode: true
register: pull_1_check
- name: Pull with policy=missing
docker_compose_v2_pull:
community.docker.docker_compose_v2_pull:
project_src: '{{ project_src }}'
policy: missing
register: pull_1
- name: Pull with policy=missing (idempotent, check)
docker_compose_v2_pull:
community.docker.docker_compose_v2_pull:
project_src: '{{ project_src }}'
policy: missing
check_mode: true
register: pull_2_check
- name: Pull with policy=missing (idempotent)
docker_compose_v2_pull:
community.docker.docker_compose_v2_pull:
project_src: '{{ project_src }}'
policy: missing
register: pull_2
- name: Make sure image is not around
docker_image_remove:
community.docker.docker_image_remove:
name: '{{ docker_test_image_simple_1 }}'
- name: Pull with policy=always (check)
docker_compose_v2_pull:
community.docker.docker_compose_v2_pull:
project_src: '{{ project_src }}'
policy: always
check_mode: true
register: pull_3_check
- name: Pull with policy=always
docker_compose_v2_pull:
community.docker.docker_compose_v2_pull:
project_src: '{{ project_src }}'
policy: always
register: pull_3
- name: Pull with policy=always (check, idempotent)
docker_compose_v2_pull:
community.docker.docker_compose_v2_pull:
project_src: '{{ project_src }}'
policy: always
check_mode: true
register: pull_4_check
- name: Pull with policy=always (idempotent)
docker_compose_v2_pull:
community.docker.docker_compose_v2_pull:
project_src: '{{ project_src }}'
policy: always
register: pull_4
- assert:
- ansible.builtin.assert:
that:
- pull_1_check is changed
- (pull_1_check.actions | selectattr('status', 'eq', 'Pulling') | first) is truthy
@ -165,32 +165,32 @@
- when: docker_compose_version is version('2.22.0', '<')
block:
- name: Pull with policy=always (check)
docker_compose_v2_pull:
community.docker.docker_compose_v2_pull:
project_src: '{{ project_src }}'
policy: always
check_mode: true
register: pull_1_check
- name: Pull with policy=always
docker_compose_v2_pull:
community.docker.docker_compose_v2_pull:
project_src: '{{ project_src }}'
policy: always
register: pull_1
- name: Pull with policy=always (again, check)
docker_compose_v2_pull:
community.docker.docker_compose_v2_pull:
project_src: '{{ project_src }}'
policy: always
check_mode: true
register: pull_2_check
- name: Pull with policy=always (again)
docker_compose_v2_pull:
community.docker.docker_compose_v2_pull:
project_src: '{{ project_src }}'
policy: always
register: pull_2
- assert:
- ansible.builtin.assert:
that:
- pull_1_check is changed
- (pull_1_check.actions | selectattr('status', 'eq', 'Pulling') | first) is truthy

View File

@ -10,20 +10,20 @@
# Create random name prefix (for services, ...)
- name: Create random container name prefix
set_fact:
ansible.builtin.set_fact:
name_prefix: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
cnames: []
dnetworks: []
- debug:
- ansible.builtin.debug:
msg: "Using name prefix {{ name_prefix }}"
# Run the tests
- block:
- name: Show docker compose --help output
command: docker compose --help
ansible.builtin.command: docker compose --help
- include_tasks: run-test.yml
- ansible.builtin.include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"
loop_control:
@ -31,7 +31,7 @@
always:
- name: "Make sure all containers are removed"
docker_container:
community.docker.docker_container:
name: "{{ item }}"
state: absent
force_kill: true
@ -39,7 +39,7 @@
diff: false
- name: "Make sure all networks are removed"
docker_network:
community.docker.docker_network:
name: "{{ item }}"
state: absent
force: true

View File

@ -4,4 +4,4 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: "Loading tasks from {{ test_name }}"
include_tasks: "{{ test_name }}"
ansible.builtin.include_tasks: "{{ test_name }}"

View File

@ -16,28 +16,28 @@
block:
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cnames: "{{ cnames + [pname ~ '-' ~ cname ~ '-1'] }}"
dnetworks: "{{ dnetworks + [pname ~ '_default'] }}"
- name: Create project directory
file:
ansible.builtin.file:
path: '{{ project_src }}'
state: directory
- name: Template default project file
copy:
ansible.builtin.copy:
dest: '{{ project_src }}/docker-compose.yml'
content: '{{ test_service }}'
- block:
- name: Start services
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
- name: Run command with command
docker_compose_v2_run:
community.docker.docker_compose_v2_run:
project_src: '{{ project_src }}'
service: '{{ cname }}'
command: /bin/sh -c "ls /"
@ -45,7 +45,7 @@
register: result_1
- name: Run command with argv
docker_compose_v2_run:
community.docker.docker_compose_v2_run:
project_src: '{{ project_src }}'
service: '{{ cname }}'
argv:
@ -58,7 +58,7 @@
failed_when: result_2.rc != 1
- name: Run detached command
docker_compose_v2_run:
community.docker.docker_compose_v2_run:
project_src: '{{ project_src }}'
service: '{{ cname }}'
command: /bin/sh -c "sleep 1"
@ -67,14 +67,14 @@
register: result_3
- name: Run command with input
docker_compose_v2_run:
community.docker.docker_compose_v2_run:
project_src: '{{ project_src }}'
service: '{{ cname }}'
command: /bin/sh -c "cat"
stdin: This is a test
register: result_4
- assert:
- ansible.builtin.assert:
that:
- result_1.rc == 0
- result_1.stderr == ""
@ -99,6 +99,6 @@
always:
- name: Cleanup
docker_compose_v2:
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: absent

View File

@ -8,8 +8,8 @@
# and should not be used as examples of how to write Ansible roles #
####################################################################
- include_tasks: test_docker_config.yml
- ansible.builtin.include_tasks: test_docker_config.yml
when: docker_py_version is version('2.6.0', '>=') and docker_api_version is version('1.30', '>=')
- fail: msg="Too old docker / docker-py version to run docker_config tests!"
- ansible.builtin.fail: msg="Too old docker / docker-py version to run docker_config tests!"
when: not(docker_py_version is version('2.6.0', '>=') and docker_api_version is version('1.30', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

View File

@ -4,108 +4,108 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- block:
- shell: "docker info --format '{% raw %}{{json .}}{% endraw %}' | {{ ansible_python_interpreter }} -m json.tool"
- ansible.builtin.shell: "docker info --format '{% raw %}{{json .}}{% endraw %}' | {{ ansible_python_interpreter }} -m json.tool"
- name: Make sure we're not already using Docker swarm
docker_swarm:
community.docker.docker_swarm:
state: absent
force: true
- shell: "docker info --format '{% raw %}{{json .}}{% endraw %}' | {{ ansible_python_interpreter }} -m json.tool"
- ansible.builtin.shell: "docker info --format '{% raw %}{{json .}}{% endraw %}' | {{ ansible_python_interpreter }} -m json.tool"
- name: Create a Swarm cluster
docker_swarm:
community.docker.docker_swarm:
name: default
state: present
advertise_addr: "{{ ansible_default_ipv4.address | default('127.0.0.1') }}"
- name: Parameter name should be required
docker_config:
community.docker.docker_config:
state: present
ignore_errors: true
register: output
- name: Assert failure when called with no name
assert:
ansible.builtin.assert:
that:
- 'output is failed'
- 'output.msg == "missing required arguments: name"'
- name: Test parameters
docker_config:
community.docker.docker_config:
name: foo
state: present
ignore_errors: true
register: output
- name: Assert failure when called with no data
assert:
ansible.builtin.assert:
that:
- 'output is failed'
- 'output.msg == "state is present but any of the following are missing: data, data_src"'
- name: Create config
docker_config:
community.docker.docker_config:
name: db_password
data: opensesame!
state: present
register: output
- name: Create variable config_id
set_fact:
ansible.builtin.set_fact:
config_id: "{{ output.config_id }}"
- name: Inspect config
command: "docker config inspect {{ config_id }}"
ansible.builtin.command: "docker config inspect {{ config_id }}"
register: inspect
ignore_errors: true
- debug:
- ansible.builtin.debug:
var: inspect
- name: Assert config creation succeeded
assert:
ansible.builtin.assert:
that:
- "'db_password' in inspect.stdout"
- "'ansible_key' in inspect.stdout"
when: inspect is not failed
- assert:
- ansible.builtin.assert:
that:
- "'is too new. Maximum supported API version is' in inspect.stderr"
when: inspect is failed
- name: Create config again
docker_config:
community.docker.docker_config:
name: db_password
data: opensesame!
state: present
register: output
- name: Assert create config is idempotent
assert:
ansible.builtin.assert:
that:
- output is not changed
- name: Write config into file
copy:
ansible.builtin.copy:
dest: "{{ remote_tmp_dir }}/data"
content: |-
opensesame!
- name: Create config again (from file)
docker_config:
community.docker.docker_config:
name: db_password
data_src: "{{ remote_tmp_dir }}/data"
state: present
register: output
- name: Assert create config is idempotent
assert:
ansible.builtin.assert:
that:
- output is not changed
- name: Create config again (base64)
docker_config:
community.docker.docker_config:
name: db_password
data: b3BlbnNlc2FtZSE=
data_is_b64: true
@ -113,53 +113,53 @@
register: output
- name: Assert create config (base64) is idempotent
assert:
ansible.builtin.assert:
that:
- output is not changed
- name: Update config
docker_config:
community.docker.docker_config:
name: db_password
data: newpassword!
state: present
register: output
- name: Assert config was updated
assert:
ansible.builtin.assert:
that:
- output is changed
- output.config_id != config_id
- name: Remove config
docker_config:
community.docker.docker_config:
name: db_password
state: absent
- name: Check that config is removed
command: "docker config inspect {{ config_id }}"
ansible.builtin.command: "docker config inspect {{ config_id }}"
register: output
ignore_errors: true
- name: Assert config was removed
assert:
ansible.builtin.assert:
that:
- output is failed
- name: Remove config
docker_config:
community.docker.docker_config:
name: db_password
state: absent
register: output
- name: Assert remove config is idempotent
assert:
ansible.builtin.assert:
that:
- output is not changed
# Rolling update
- name: Create rolling config
docker_config:
community.docker.docker_config:
name: rolling_password
data: opensesame!
rolling_versions: true
@ -167,32 +167,32 @@
register: original_output
- name: Create variable config_id
set_fact:
ansible.builtin.set_fact:
config_id: "{{ original_output.config_id }}"
- name: Inspect config
command: "docker config inspect {{ config_id }}"
ansible.builtin.command: "docker config inspect {{ config_id }}"
register: inspect
ignore_errors: true
- debug:
- ansible.builtin.debug:
var: inspect
- name: Assert config creation succeeded
assert:
ansible.builtin.assert:
that:
- "'rolling_password' in inspect.stdout"
- "'ansible_key' in inspect.stdout"
- "'ansible_version' in inspect.stdout"
- original_output.config_name == 'rolling_password_v1'
when: inspect is not failed
- assert:
- ansible.builtin.assert:
that:
- "'is too new. Maximum supported API version is' in inspect.stderr"
when: inspect is failed
- name: Create config again
docker_config:
community.docker.docker_config:
name: rolling_password
data: newpassword!
rolling_versions: true
@ -200,7 +200,7 @@
register: new_output
- name: Assert that new version is created
assert:
ansible.builtin.assert:
that:
- new_output is changed
- new_output.config_id != original_output.config_id
@ -208,28 +208,28 @@
- new_output.config_name == 'rolling_password_v2'
- name: Remove rolling configs
docker_config:
community.docker.docker_config:
name: rolling_password
rolling_versions: true
state: absent
- name: Check that config is removed
command: "docker config inspect {{ original_output.config_id }}"
ansible.builtin.command: "docker config inspect {{ original_output.config_id }}"
register: output
ignore_errors: true
- name: Assert config was removed
assert:
ansible.builtin.assert:
that:
- output is failed
- name: Check that config is removed
command: "docker config inspect {{ new_output.config_id }}"
ansible.builtin.command: "docker config inspect {{ new_output.config_id }}"
register: output
ignore_errors: true
- name: Assert config was removed
assert:
ansible.builtin.assert:
that:
- output is failed
@ -239,13 +239,13 @@
block:
- name: Create regular config
docker_config:
community.docker.docker_config:
name: db_password
data: opensesame!
state: present
- name: Update config with template_driver
docker_config:
community.docker.docker_config:
name: db_password
data: opensesame!
template_driver: golang
@ -253,12 +253,12 @@
register: output
- name: Assert config was updated
assert:
ansible.builtin.assert:
that:
- output is changed
- name: Invalid template_driver
docker_config:
community.docker.docker_config:
name: db_password
data: opensesame!
template_driver: "not a template driver"
@ -267,13 +267,13 @@
register: output
- name: Assert failure when called with invalid template_driver
assert:
ansible.builtin.assert:
that:
- 'output is failed'
- 'output.msg == "value of template_driver must be one of: golang, got: not a template driver"'
- name: Create config again
docker_config:
community.docker.docker_config:
name: db_password
data: opensesame!
template_driver: golang
@ -281,13 +281,13 @@
register: output
- name: Assert create config is idempotent
assert:
ansible.builtin.assert:
that:
- output is not changed
# data is the docker swarm's name
- name: Update config with template data
docker_config:
community.docker.docker_config:
name: db_password
data: "{{ '{{' }} .Service.Name {{ '}}' }}"
template_driver: golang
@ -295,15 +295,15 @@
register: output
- name: Inspect config
command: "docker config inspect {{ output.config_id }}"
ansible.builtin.command: "docker config inspect {{ output.config_id }}"
register: inspect
- name: Show inspection result
debug:
ansible.builtin.debug:
var: inspect
- name: Assert config creation succeeded
assert:
ansible.builtin.assert:
that:
- "'db_password' in inspect.stdout"
- "'ansible_key' in inspect.stdout"
@ -313,22 +313,22 @@
- "'\"Name\": \"golang\"' in inspect.stdout"
- name: Remove config
docker_config:
community.docker.docker_config:
name: db_password
state: absent
- name: Check that config is removed
command: "docker config inspect {{ output.config_id }}"
ansible.builtin.command: "docker config inspect {{ output.config_id }}"
register: output
ignore_errors: true
- name: Assert config was removed
assert:
ansible.builtin.assert:
that:
- output is failed
always:
- name: Remove a Swarm cluster
docker_swarm:
community.docker.docker_swarm:
state: absent
force: true

View File

@ -9,36 +9,36 @@
####################################################################
- name: Gather facts on controller
setup:
ansible.builtin.setup:
gather_subset: '!all'
delegate_to: localhost
delegate_facts: true
run_once: true
- name: Make sure ipaddress is available on controller
pip:
ansible.builtin.pip:
name: ipaddress
delegate_to: localhost
when: hostvars['localhost'].ansible_facts.python.version.major < 3
# Create random name prefix (for containers, networks, ...)
- name: Create random container name prefix
set_fact:
ansible.builtin.set_fact:
cname_prefix: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
cnames: []
inames: []
dnetworks: []
- debug:
- ansible.builtin.debug:
msg: "Using container name prefix {{ cname_prefix }}"
- name: Retrieve docker host info
docker_host_info:
community.docker.docker_host_info:
register: docker_host_info
# Run the tests
- block:
- include_tasks: run-test.yml
- ansible.builtin.include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"
loop_control:
@ -46,18 +46,18 @@
always:
- name: "Make sure all containers are removed"
docker_container:
community.docker.docker_container:
name: "{{ item }}"
state: absent
force_kill: true
with_items: "{{ cnames }}"
diff: false
- name: "Make sure all images are removed"
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ item }}"
with_items: "{{ inames }}"
- name: "Make sure all networks are removed"
docker_network:
community.docker.docker_network:
name: "{{ item }}"
state: absent
force: true
@ -66,5 +66,5 @@
when: docker_api_version is version('1.25', '>=')
- fail: msg="Too old docker / docker-py version to run all docker_container tests!"
- ansible.builtin.fail: msg="Too old docker / docker-py version to run all docker_container tests!"
when: not(docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

View File

@ -4,4 +4,4 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: "Loading tasks from {{ test_name }}"
include_tasks: "{{ test_name }}"
ansible.builtin.include_tasks: "{{ test_name }}"

View File

@ -4,10 +4,10 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cname: "{{ cname_prefix ~ '-comparisons' }}"
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cnames: "{{ cnames + [cname] }}"
####################################################################
@ -15,7 +15,7 @@
####################################################################
- name: value
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -24,7 +24,7 @@
register: value_1
- name: value (change, ignore)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -36,7 +36,7 @@
register: value_2
- name: value (change, strict)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -48,13 +48,13 @@
register: value_3
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- assert:
- ansible.builtin.assert:
that:
- value_1 is changed
- value_2 is not changed
@ -65,7 +65,7 @@
####################################################################
- name: list
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -76,7 +76,7 @@
register: list_1
- name: list (change, ignore)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -89,7 +89,7 @@
register: list_2
- name: list (change, strict)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -102,13 +102,13 @@
register: list_3
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- assert:
- ansible.builtin.assert:
that:
- list_1 is changed
- list_2 is not changed
@ -119,7 +119,7 @@
####################################################################
- name: set
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -130,7 +130,7 @@
register: set_1
- name: set (change, ignore)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -145,7 +145,7 @@
register: set_2
- name: set (change, allow_more_present)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -160,7 +160,7 @@
register: set_3
- name: set (change, allow_more_present)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -174,7 +174,7 @@
register: set_4
- name: set (change, strict)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -188,13 +188,13 @@
register: set_5
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- assert:
- ansible.builtin.assert:
that:
- set_1 is changed
- set_2 is not changed
@ -207,7 +207,7 @@
####################################################################
- name: set(dict)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -218,7 +218,7 @@
register: set_dict_1
- name: set(dict) (change, ignore)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -233,7 +233,7 @@
register: set_dict_2
- name: set(dict) (change, allow_more_present)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -248,7 +248,7 @@
register: set_dict_3
- name: set(dict) (change, allow_more_present)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -262,7 +262,7 @@
register: set_dict_4
- name: set(dict) (change, strict)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -276,13 +276,13 @@
register: set_dict_5
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- assert:
- ansible.builtin.assert:
that:
- set_dict_1 is changed
- set_dict_2 is not changed
@ -295,7 +295,7 @@
####################################################################
- name: dict
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -306,7 +306,7 @@
register: dict_1
- name: dict (change, ignore)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -321,7 +321,7 @@
register: dict_2
- name: dict (change, allow_more_present)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -336,7 +336,7 @@
register: dict_3
- name: dict (change, allow_more_present)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -350,7 +350,7 @@
register: dict_4
- name: dict (change, strict)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -364,13 +364,13 @@
register: dict_5
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- assert:
- ansible.builtin.assert:
that:
- dict_1 is changed
- dict_2 is not changed
@ -384,11 +384,11 @@
- name: Pull {{ docker_test_image_hello_world }} image to make sure wildcard_2 test succeeds
# If the image isn't there, it will pull it and return 'changed'.
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ docker_test_image_hello_world }}"
- name: wildcard
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -402,7 +402,7 @@
register: wildcard_1
- name: wildcard (change, ignore)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_hello_world }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -418,7 +418,7 @@
register: wildcard_2
- name: wildcard (change, strict)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -435,7 +435,7 @@
register: wildcard_3
- name: wildcard (no change, strict)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -452,13 +452,13 @@
register: wildcard_4
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- assert:
- ansible.builtin.assert:
that:
- wildcard_1 is changed
- wildcard_2 is not changed

View File

@ -4,10 +4,10 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cname: "{{ cname_prefix ~ '-hi' }}"
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cnames: "{{ cnames + [cname] }}"
####################################################################
@ -15,7 +15,7 @@
####################################################################
- name: Start container (check)
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
@ -25,7 +25,7 @@
register: start_1
- name: Start container
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
@ -34,7 +34,7 @@
register: start_2
- name: Start container (idempotent)
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
@ -43,7 +43,7 @@
register: start_3
- name: Start container (idempotent check)
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
image: "{{ docker_test_image_alpine }}"
state: started
@ -52,13 +52,13 @@
register: start_4
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- assert:
- ansible.builtin.assert:
that:
- start_1 is changed
- start_2 is changed
@ -70,7 +70,7 @@
####################################################################
- name: Start container (check)
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
@ -80,7 +80,7 @@
register: start_1
- name: Start container
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
@ -89,7 +89,7 @@
register: start_2
- name: Start container (idempotent)
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
@ -98,7 +98,7 @@
register: start_3
- name: Start container (idempotent check)
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
@ -108,13 +108,13 @@
register: start_4
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- assert:
- ansible.builtin.assert:
that:
- start_1 is changed
- start_2 is changed

View File

@ -4,34 +4,34 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cname: "{{ cname_prefix ~ '-hi' }}"
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cnames: "{{ cnames + [cname] }}"
- name: Prepare container
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
image: "{{ docker_test_image_healthcheck }}"
command: '10m'
state: stopped
register: healthy_1
- debug: var=healthy_1.container.State
- ansible.builtin.debug: var=healthy_1.container.State
- name: Start container (not healthy in time)
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: healthy
healthy_wait_timeout: 1
register: healthy_2
ignore_errors: true
- debug: var=healthy_2.container.State
- ansible.builtin.debug: var=healthy_2.container.State
- name: Prepare container
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
image: "{{ docker_test_image_healthcheck }}"
command: '10m 5s'
@ -39,23 +39,23 @@
force_kill: true
register: healthy_3
- debug: var=healthy_3.container.State
- ansible.builtin.debug: var=healthy_3.container.State
- name: Start container (healthy in time)
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: healthy
healthy_wait_timeout: 10
register: healthy_4
- debug: var=healthy_4.container.State
- ansible.builtin.debug: var=healthy_4.container.State
- name: Cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
- assert:
- ansible.builtin.assert:
that:
- healthy_2 is failed
- healthy_2.container.State.Health.Status == "starting"

View File

@ -4,14 +4,14 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cname: "{{ cname_prefix ~ '-iid' }}"
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cnames: "{{ cnames + [cname] }}"
- name: Pull images
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ image }}"
loop:
- "{{ docker_test_image_hello_world }}"
@ -20,22 +20,22 @@
loop_var: image
- name: Get image ID of {{ docker_test_image_hello_world }} and {{ docker_test_image_alpine }} images
docker_image_info:
community.docker.docker_image_info:
name:
- "{{ docker_test_image_hello_world }}"
- "{{ docker_test_image_alpine }}"
register: image_info
- assert:
- ansible.builtin.assert:
that:
- image_info.images | length == 2
- name: Print image IDs
debug:
ansible.builtin.debug:
msg: "{{ docker_test_image_hello_world }}: {{ image_info.images[0].Id }}; {{ docker_test_image_alpine }}: {{ image_info.images[1].Id }}"
- name: Create container with {{ docker_test_image_hello_world }} image via ID
docker_container:
community.docker.docker_container:
image: "{{ image_info.images[0].Id }}"
name: "{{ cname }}"
state: present
@ -43,7 +43,7 @@
register: create_1
- name: Create container with {{ docker_test_image_hello_world }} image via ID (idempotent)
docker_container:
community.docker.docker_container:
image: "{{ image_info.images[0].Id }}"
name: "{{ cname }}"
state: present
@ -51,7 +51,7 @@
register: create_2
- name: Create container with {{ docker_test_image_alpine }} image via ID
docker_container:
community.docker.docker_container:
image: "{{ image_info.images[1].Id }}"
name: "{{ cname }}"
state: present
@ -59,7 +59,7 @@
register: create_3
- name: Create container with {{ docker_test_image_alpine }} image via ID (idempotent)
docker_container:
community.docker.docker_container:
image: "{{ image_info.images[1].Id }}"
name: "{{ cname }}"
state: present
@ -68,12 +68,12 @@
- name: Untag image
# Image will not be deleted since the container still uses it
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ docker_test_image_alpine }}"
force: true
- name: Create container with {{ docker_test_image_alpine }} image via name (check mode, will pull, same image)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
name: "{{ cname }}"
state: present
@ -82,7 +82,7 @@
check_mode: true
- name: Create container with {{ docker_test_image_alpine }} image via name (will pull, same image)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
name: "{{ cname }}"
state: present
@ -90,13 +90,13 @@
register: create_6
- name: Cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- assert:
- ansible.builtin.assert:
that:
- create_1 is changed
- create_2 is not changed
@ -108,7 +108,7 @@
- create_6.container.Id == create_4.container.Id # make sure container wasn't recreated
- name: Create container with {{ docker_test_image_digest_base }} image via old digest
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_digest_base }}@sha256:{{ docker_test_image_digest_v1 }}"
name: "{{ cname }}"
state: present
@ -116,7 +116,7 @@
register: digest_1
- name: Create container with {{ docker_test_image_digest_base }} image via old digest (idempotent)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_digest_base }}@sha256:{{ docker_test_image_digest_v1 }}"
name: "{{ cname }}"
state: present
@ -124,7 +124,7 @@
register: digest_2
- name: Create container with {{ docker_test_image_digest_base }} image via old digest (idempotent, pull)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_digest_base }}@sha256:{{ docker_test_image_digest_v1 }}"
name: "{{ cname }}"
pull: true
@ -133,7 +133,7 @@
register: digest_3
- name: Update container with {{ docker_test_image_digest_base }} image via new digest
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_digest_base }}@sha256:{{ docker_test_image_digest_v2 }}"
name: "{{ cname }}"
state: present
@ -141,13 +141,13 @@
register: digest_4
- name: Cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- assert:
- ansible.builtin.assert:
that:
- digest_1 is changed
- digest_2 is not changed

View File

@ -4,12 +4,12 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cname: "{{ cname_prefix ~ '-mounts' }}"
cname_h1: "{{ cname_prefix ~ '-mounts-h1' }}"
cname_h2: "{{ cname_prefix ~ '-mounts-h2' }}"
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cnames: "{{ cnames + [cname, cname_h1, cname_h2] }}"
####################################################################
@ -23,7 +23,7 @@
####################################################################
- name: mounts
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -39,7 +39,7 @@
register: mounts_1
- name: mounts (idempotency)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -55,7 +55,7 @@
register: mounts_2
- name: mounts (less mounts)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -67,7 +67,7 @@
register: mounts_3
- name: mounts (more mounts)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -84,7 +84,7 @@
register: mounts_4
- name: mounts (different modes)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -101,7 +101,7 @@
register: mounts_5
- name: mounts (endpoint collision)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -119,7 +119,7 @@
ignore_errors: true
- name: mounts (anonymous volume)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -131,7 +131,7 @@
register: mounts_7
- name: mounts (anonymous volume idempotency)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -143,13 +143,13 @@
register: mounts_8
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- assert:
- ansible.builtin.assert:
that:
- mounts_1 is changed
- mounts_2 is not changed
@ -166,7 +166,7 @@
####################################################################
- name: tmpfs
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -184,7 +184,7 @@
register: tmpfs_1
- name: tmpfs (idempotency)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -202,7 +202,7 @@
register: tmpfs_2
- name: tmpfs (more mounts)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -224,7 +224,7 @@
register: tmpfs_3
- name: tmpfs (change mode)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -238,7 +238,7 @@
register: tmpfs_4
- name: tmpfs (change size)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -252,13 +252,13 @@
register: tmpfs_5
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- assert:
- ansible.builtin.assert:
that:
- tmpfs_1 is changed
- tmpfs_2 is not changed
@ -271,7 +271,7 @@
####################################################################
- name: mounts + volumes
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -286,7 +286,7 @@
register: mounts_volumes_1
- name: mounts + volumes (idempotency)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -301,7 +301,7 @@
register: mounts_volumes_2
- name: mounts + volumes (switching)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -317,7 +317,7 @@
register: mounts_volumes_3
- name: mounts + volumes (collision, should fail)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -334,13 +334,13 @@
ignore_errors: true
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- assert:
- ansible.builtin.assert:
that:
- mounts_volumes_1 is changed
- mounts_volumes_2 is not changed
@ -353,7 +353,7 @@
####################################################################
- name: volume_driver
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -362,7 +362,7 @@
register: volume_driver_1
- name: volume_driver (idempotency)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -371,7 +371,7 @@
register: volume_driver_2
- name: volume_driver (change)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -381,13 +381,13 @@
register: volume_driver_3
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- assert:
- ansible.builtin.assert:
that:
- volume_driver_1 is changed
- volume_driver_2 is not changed
@ -398,7 +398,7 @@
####################################################################
- name: volumes
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -410,7 +410,7 @@
register: volumes_1
- name: volumes (idempotency)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -422,7 +422,7 @@
register: volumes_2
- name: volumes (less volumes)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -432,7 +432,7 @@
register: volumes_3
- name: volumes (more volumes)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -444,7 +444,7 @@
register: volumes_4
- name: volumes (different modes)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -456,7 +456,7 @@
register: volumes_5
- name: volumes (collision)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -469,13 +469,13 @@
ignore_errors: true
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- assert:
- ansible.builtin.assert:
that:
- volumes_1 is changed
- volumes_1.container.Config.Volumes | length == 1
@ -493,7 +493,7 @@
####################################################################
- name: start helpers
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ container_name }}"
@ -507,7 +507,7 @@
loop_var: container_name
- name: volumes_from
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -516,7 +516,7 @@
register: volumes_from_1
- name: volumes_from (idempotency)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -525,7 +525,7 @@
register: volumes_from_2
- name: volumes_from (change)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -535,7 +535,7 @@
register: volumes_from_3
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ container_name }}"
state: absent
force_kill: true
@ -547,7 +547,7 @@
loop_var: container_name
diff: false
- assert:
- ansible.builtin.assert:
that:
- volumes_from_1 is changed
- volumes_from_2 is not changed

View File

@ -4,19 +4,19 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cname: "{{ cname_prefix ~ '-network' }}"
cname_h1: "{{ cname_prefix ~ '-network-h1' }}"
nname_1: "{{ cname_prefix ~ '-network-1' }}"
nname_2: "{{ cname_prefix ~ '-network-2' }}"
nname_3: "{{ cname_prefix ~ '-network-3' }}"
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cnames: "{{ cnames + [cname, cname_h1] }}"
dnetworks: "{{ dnetworks + [nname_1, nname_2, nname_3] }}"
- name: Create networks
docker_network:
community.docker.docker_network:
name: "{{ network_name }}"
state: present
loop:
@ -25,14 +25,14 @@
loop_control:
loop_var: network_name
- set_fact:
- ansible.builtin.set_fact:
subnet_ipv4_base: 10.{{ 16 + (240 | random) }}.{{ 16 + (240 | random) }}
subnet_ipv6_base: fdb6:feea:{{ '%0.4x:%0.4x' | format(65536 | random, 65536 | random) }}
# If netaddr would be installed on the controller, one could do:
# subnet_ipv4: "10.{{ 16 + (240 | random) }}.{{ 16 + (240 | random) }}.0/24"
# subnet_ipv6: "fdb6:feea:{{ '%0.4x:%0.4x' | format(65536 | random, 65536 | random) }}::/64"
- set_fact:
- ansible.builtin.set_fact:
subnet_ipv4: "{{ subnet_ipv4_base }}.0/24"
subnet_ipv6: "{{ subnet_ipv6_base }}::/64"
nname_3_ipv4_2: "{{ subnet_ipv4_base }}.2"
@ -49,11 +49,11 @@
# nname_3_ipv6_3: "{{ subnet_ipv6 | ansible.netcommon.next_nth_usable(3) }}"
# nname_3_ipv6_4: "{{ subnet_ipv6 | ansible.netcommon.next_nth_usable(4) }}"
- debug:
- ansible.builtin.debug:
msg: "Chose random IPv4 subnet {{ subnet_ipv4 }} and random IPv6 subnet {{ subnet_ipv6 }}"
- name: Create network with fixed IPv4 and IPv6 subnets
docker_network:
community.docker.docker_network:
name: "{{ nname_3 }}"
enable_ipv6: true
ipam_config:
@ -66,7 +66,7 @@
####################################################################
- name: network_mode
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -75,7 +75,7 @@
register: network_mode_1
- name: network_mode (idempotency)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -84,7 +84,7 @@
register: network_mode_2
- name: network_mode (change)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -94,7 +94,7 @@
register: network_mode_3
- name: network_mode (container mode setup)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname_h1 }}"
@ -102,7 +102,7 @@
register: cname_h1_id
- name: network_mode (container mode)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -112,7 +112,7 @@
register: network_mode_4
- name: network_mode (container mode idempotency)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -121,7 +121,7 @@
register: network_mode_5
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ container_name }}"
state: absent
force_kill: true
@ -132,7 +132,7 @@
loop_var: container_name
diff: false
- assert:
- ansible.builtin.assert:
that:
- network_mode_1 is changed
- network_mode_1.container.HostConfig.NetworkMode == 'host'
@ -150,7 +150,7 @@
####################################################################
- name: networks_cli_compatible=no, networks w/o purge_networks
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -162,7 +162,7 @@
register: networks_1
- name: networks_cli_compatible=no, networks w/o purge_networks
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -174,7 +174,7 @@
register: networks_2
- name: networks_cli_compatible=no, networks, purge_networks
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -189,7 +189,7 @@
register: networks_3
- name: networks_cli_compatible=no, networks, purge_networks (idempotency)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -203,7 +203,7 @@
register: networks_4
- name: networks_cli_compatible=no, networks (less networks)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -214,7 +214,7 @@
register: networks_5
- name: networks_cli_compatible=no, networks, purge_networks (less networks)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -228,7 +228,7 @@
register: networks_6
- name: networks_cli_compatible=no, networks, purge_networks (more networks)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -243,13 +243,13 @@
register: networks_7
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- assert:
- ansible.builtin.assert:
that:
# networks_1 has networks default, 'bridge', nname_1
- networks_1 is changed
@ -293,7 +293,7 @@
####################################################################
- name: networks_cli_compatible=yes, networks specified
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -308,7 +308,7 @@
register: networks_1
- name: networks_cli_compatible=yes, networks specified
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -320,14 +320,14 @@
register: networks_2
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- name: networks_cli_compatible=yes, empty networks list specified
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -337,7 +337,7 @@
register: networks_3
- name: networks_cli_compatible=yes, empty networks list specified
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -347,7 +347,7 @@
register: networks_4
- name: networks_cli_compatible=yes, empty networks list specified, purge_networks
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -360,14 +360,14 @@
register: networks_5
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- name: networks_cli_compatible=yes, networks not specified
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -377,7 +377,7 @@
register: networks_6
- name: networks_cli_compatible=yes, networks not specified
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -386,7 +386,7 @@
register: networks_7
- name: networks_cli_compatible=yes, networks empty, purge_networks
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -399,15 +399,15 @@
register: networks_8
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- debug: var=networks_3
- ansible.builtin.debug: var=networks_3
- assert:
- ansible.builtin.assert:
that:
# networks_1 has networks nname_1, nname_2
- networks_1 is changed
@ -447,7 +447,7 @@
####################################################################
- name: create container with one network
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -458,7 +458,7 @@
register: networks_1
- name: different networks, comparisons=ignore
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -472,7 +472,7 @@
register: networks_2
- name: less networks, comparisons=ignore
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -484,7 +484,7 @@
register: networks_3
- name: less networks, comparisons=allow_more_present
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -496,7 +496,7 @@
register: networks_4
- name: different networks, comparisons=allow_more_present
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -511,7 +511,7 @@
register: networks_5
- name: different networks, comparisons=strict
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -525,7 +525,7 @@
register: networks_6
- name: less networks, comparisons=strict
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -538,13 +538,13 @@
register: networks_7
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- assert:
- ansible.builtin.assert:
that:
# networks_1 has networks nname_1
- networks_1 is changed
@ -580,7 +580,7 @@
####################################################################
- name: create container (stopped) with one network and fixed IP
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -593,7 +593,7 @@
register: networks_1
- name: create container (stopped) with one network and fixed IP (idempotent)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -606,7 +606,7 @@
register: networks_2
- name: create container (stopped) with one network and fixed IP (different IPv4)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -619,7 +619,7 @@
register: networks_3
- name: create container (stopped) with one network and fixed IP (different IPv6)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -632,13 +632,13 @@
register: networks_4
- name: create container (started) with one network and fixed IP
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: started
register: networks_5
- name: create container (started) with one network and fixed IP (different IPv4)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -652,7 +652,7 @@
register: networks_6
- name: create container (started) with one network and fixed IP (different IPv6)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -666,7 +666,7 @@
register: networks_7
- name: create container (started) with one network and fixed IP (idempotent)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -679,13 +679,13 @@
register: networks_8
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- assert:
- ansible.builtin.assert:
that:
- networks_1 is changed
- networks_1.container.NetworkSettings.Networks[nname_3].IPAMConfig.IPv4Address == nname_3_ipv4_2
@ -733,7 +733,7 @@
####################################################################
- name: Delete networks
docker_network:
community.docker.docker_network:
name: "{{ network_name }}"
state: absent
force: true

View File

@ -4,11 +4,11 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cname: "{{ cname_prefix ~ '-options' }}"
cname2: "{{ cname_prefix ~ '-options-h1' }}"
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cnames: "{{ cnames + [cname, cname2] }}"
####################################################################
@ -16,7 +16,7 @@
####################################################################
- name: published_ports -- non-closing square bracket
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -27,7 +27,7 @@
ignore_errors: true
- name: published_ports -- forgot square brackets for IPv6
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -38,7 +38,7 @@
ignore_errors: true
- name: published_ports -- disallow hostnames
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -48,7 +48,7 @@
register: published_ports_3
ignore_errors: true
- assert:
- ansible.builtin.assert:
that:
- published_ports_1 is failed
- published_ports_1.msg == 'Cannot find closing "]" in input "[::1:2000:3000" for opening "[" at index 1!'
@ -62,7 +62,7 @@
####################################################################
- name: published_ports -- port range
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -77,7 +77,7 @@
register: published_ports_1
- name: published_ports -- port range (idempotency)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -92,7 +92,7 @@
register: published_ports_2
- name: published_ports -- port range (different range)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -107,13 +107,13 @@
register: published_ports_3
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- assert:
- ansible.builtin.assert:
that:
- published_ports_1 is changed
- published_ports_2 is not changed
@ -124,7 +124,7 @@
####################################################################
- name: published_ports -- one-element container port range
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ item }}"
@ -138,7 +138,7 @@
register: published_ports_1
- name: published_ports -- one-element container port range (idempotency)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ item }}"
@ -152,7 +152,7 @@
register: published_ports_2
- name: published_ports -- one-element container port range (different range)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ item }}"
@ -166,7 +166,7 @@
register: published_ports_3
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ item }}"
state: absent
force_kill: true
@ -175,7 +175,7 @@
- '{{ cname2 }}'
diff: false
- assert:
- ansible.builtin.assert:
that:
- published_ports_1 is changed
- published_ports_2 is not changed
@ -188,7 +188,7 @@
- when: docker_host_info.host_info.ServerVersion is version('27.0.0', '<')
block:
- name: published_ports -- IPv6
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -199,7 +199,7 @@
register: published_ports_1
- name: published_ports -- IPv6 (idempotency)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -210,7 +210,7 @@
register: published_ports_2
- name: published_ports -- IPv6 (different IP)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -221,7 +221,7 @@
register: published_ports_3
- name: published_ports -- IPv6 (hostname)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -233,13 +233,13 @@
ignore_errors: true
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- assert:
- ansible.builtin.assert:
that:
- published_ports_1 is changed
- published_ports_2 is not changed
@ -250,7 +250,7 @@
## publish_all_ports ###############################################
####################################################################
- set_fact:
- ansible.builtin.set_fact:
publish_all_ports_test_cases:
- test_name: no_options
changed: true
@ -306,7 +306,7 @@
changed: false
- name: publish_all_ports ({{ test_case.test_name }})
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -319,7 +319,7 @@
loop_var: test_case
loop: "{{ publish_all_ports_test_cases }}"
- assert:
- ansible.builtin.assert:
that:
- publish_all_ports.results[index].changed == test_case.changed
loop: "{{ publish_all_ports_test_cases }}"

View File

@ -5,21 +5,21 @@
# Regression test for https://github.com/ansible/ansible/pull/45700
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cname: "{{ cname_prefix ~ '-45700' }}"
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cnames: "{{ cnames + [cname] }}"
- name: Start container
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
- name: Stop container with a lot of invalid options
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
force_kill: true
# Some options with "invalid" values, which would

View File

@ -4,10 +4,10 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cname: "{{ cname_prefix ~ '-hi' }}"
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cnames: "{{ cnames + [cname] }}"
####################################################################
@ -15,7 +15,7 @@
####################################################################
- name: Create container (check)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -24,7 +24,7 @@
register: create_1
- name: Create container
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -32,7 +32,7 @@
register: create_2
- name: Create container (idempotent)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -40,7 +40,7 @@
register: create_3
- name: Create container (idempotent check)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -48,7 +48,7 @@
check_mode: true
register: create_4
- assert:
- ansible.builtin.assert:
that:
- create_1 is changed
- create_2 is changed
@ -60,32 +60,32 @@
####################################################################
- name: Start container (check)
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: started
check_mode: true
register: start_1
- name: Start container
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: started
register: start_2
- name: Start container (idempotent)
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: started
register: start_3
- name: Start container (idempotent check)
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: started
check_mode: true
register: start_4
- assert:
- ansible.builtin.assert:
that:
- start_1 is changed
- start_2 is changed
@ -97,7 +97,7 @@
####################################################################
- name: Present check for running container (check)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -106,14 +106,14 @@
register: present_check_1
- name: Present check for running container
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: present
register: present_check_2
- assert:
- ansible.builtin.assert:
that:
- present_check_1 is not changed
- present_check_2 is not changed
@ -123,13 +123,13 @@
####################################################################
- name: Remove container (setup for starting from scratch)
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
- name: Start container from scratch (check)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
stop_timeout: 1
@ -139,7 +139,7 @@
register: start_scratch_1
- name: Start container from scratch
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
stop_timeout: 1
@ -148,7 +148,7 @@
register: start_scratch_2
- name: Start container from scratch (idempotent)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
stop_timeout: 1
@ -157,7 +157,7 @@
register: start_scratch_3
- name: Start container from scratch (idempotent check)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
stop_timeout: 1
@ -166,7 +166,7 @@
check_mode: true
register: start_scratch_4
- assert:
- ansible.builtin.assert:
that:
- start_scratch_1 is changed
- start_scratch_2 is changed
@ -178,7 +178,7 @@
####################################################################
- name: Recreating container (created)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -187,7 +187,7 @@
register: recreate_1
- name: Recreating container (created, recreate, check mode)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -198,7 +198,7 @@
check_mode: true
- name: Recreating container (created, recreate)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -208,7 +208,7 @@
register: recreate_3
- name: Recreating container (started)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -217,7 +217,7 @@
register: recreate_4
- name: Recreating container (started, recreate, check mode)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -229,7 +229,7 @@
check_mode: true
- name: Recreating container (started, recreate)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -240,18 +240,18 @@
register: recreate_6
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- debug: var=recreate_1
- debug: var=recreate_3
- debug: var=recreate_4
- debug: var=recreate_6
- ansible.builtin.debug: var=recreate_1
- ansible.builtin.debug: var=recreate_3
- ansible.builtin.debug: var=recreate_4
- ansible.builtin.debug: var=recreate_6
- assert:
- ansible.builtin.assert:
that:
- recreate_2 is changed
- recreate_3 is changed
@ -269,7 +269,7 @@
####################################################################
- name: Restarting
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -280,7 +280,7 @@
register: restart_1
- name: Restarting (restart, check mode)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -292,7 +292,7 @@
check_mode: true
- name: Restarting (restart)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -303,7 +303,7 @@
register: restart_3
- name: Restarting (verify volumes)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -314,13 +314,13 @@
register: restart_4
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- assert:
- ansible.builtin.assert:
that:
- restart_1 is changed
- restart_2 is changed
@ -333,7 +333,7 @@
####################################################################
- name: Stop container (check)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
name: "{{ cname }}"
state: stopped
@ -342,7 +342,7 @@
register: stop_1
- name: Stop container
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
name: "{{ cname }}"
state: stopped
@ -350,7 +350,7 @@
register: stop_2
- name: Stop container (idempotent)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
name: "{{ cname }}"
state: stopped
@ -358,7 +358,7 @@
register: stop_3
- name: Stop container (idempotent check)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
name: "{{ cname }}"
state: stopped
@ -366,7 +366,7 @@
check_mode: true
register: stop_4
- assert:
- ansible.builtin.assert:
that:
- stop_1 is changed
- stop_2 is changed
@ -378,32 +378,32 @@
####################################################################
- name: Remove container (check)
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
check_mode: true
register: remove_1
- name: Remove container
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
register: remove_2
- name: Remove container (idempotent)
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
register: remove_3
- name: Remove container (idempotent check)
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
check_mode: true
register: remove_4
- assert:
- ansible.builtin.assert:
that:
- remove_1 is changed
- remove_2 is changed
@ -415,14 +415,14 @@
####################################################################
- name: Start container (setup for removing from running)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
- name: Remove container from running (check)
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
@ -430,28 +430,28 @@
register: remove_from_running_1
- name: Remove container from running
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
register: remove_from_running_2
- name: Remove container from running (idempotent)
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
register: remove_from_running_3
- name: Remove container from running (idempotent check)
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
check_mode: true
register: remove_from_running_4
- assert:
- ansible.builtin.assert:
that:
- remove_from_running_1 is changed
- remove_from_running_2 is changed

View File

@ -4,20 +4,20 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cname: "{{ cname_prefix ~ '-update' }}"
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cnames: "{{ cnames + [cname] }}"
# We do not test cpuset_cpus and cpuset_mems since changing it fails if the system does
# not have 'enough' CPUs. We do not test kernel_memory since it is deprecated and fails.
- set_fact:
- ansible.builtin.set_fact:
has_blkio_weight: true
- name: Create container
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -37,16 +37,16 @@
- when: create is failed
block:
- name: Make sure container is not there
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
- when: "'setting cgroup config for procHooks process caused: failed to write' in create.msg and 'io.bfq.weight' in create.msg"
set_fact:
ansible.builtin.set_fact:
has_blkio_weight: false
- name: Create container again
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -63,11 +63,11 @@
register: create_2
- when: "'setting cgroup config for procHooks process caused: failed to write' in create.msg and 'io.bfq.weight' in create.msg"
set_fact:
ansible.builtin.set_fact:
create: "{{ create_2 }}"
- name: Update values
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -85,7 +85,7 @@
diff: true
- name: Update values again
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -103,7 +103,7 @@
diff: true
- name: Recreate container
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 20m"' # this will force re-creation
name: "{{ cname }}"
@ -122,14 +122,14 @@
diff: true
- name: cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false
- name: Check general things
assert:
ansible.builtin.assert:
that:
- create is changed
- update is changed
@ -144,7 +144,7 @@
- create.container.Id != recreate.container.Id
- name: Check diff for first update
assert:
ansible.builtin.assert:
that:
# blkio_weight sometimes cannot be set, then we end up with 0 instead of the value we had
- >-
@ -169,7 +169,7 @@
- update.diff.after.restart_retries == 2
- name: Check diff for second update
assert:
ansible.builtin.assert:
that:
- >-
not has_blkio_weight or update2.diff.before.blkio_weight == 234 or ('Docker warning: Your kernel does not support Block I/O weight or the cgroup is not mounted. Weight discarded.' in (create.warnings | default([])))
@ -194,7 +194,7 @@
- update2.diff.after.restart_retries == 0
- name: Check diff for recreation
assert:
ansible.builtin.assert:
that:
- >-
not has_blkio_weight or recreate.diff.before.blkio_weight == 135 or ('Docker warning: Your kernel does not support Block I/O weight or the cgroup is not mounted. Weight discarded.' in (create.warnings | default([])))

View File

@ -9,7 +9,7 @@
####################################################################
- name: Gather facts on controller
setup:
ansible.builtin.setup:
gather_subset: '!all'
delegate_to: localhost
delegate_facts: true
@ -17,16 +17,16 @@
# Create random name prefix (for containers)
- name: Create random container name prefix
set_fact:
ansible.builtin.set_fact:
cname_prefix: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
cnames: []
- debug:
- ansible.builtin.debug:
msg: "Using container name prefix {{ cname_prefix }}"
# Run the tests
- block:
- include_tasks: run-test.yml
- ansible.builtin.include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"
loop_control:
@ -34,7 +34,7 @@
always:
- name: "Make sure all containers are removed"
docker_container:
community.docker.docker_container:
name: "{{ item }}"
state: absent
force_kill: true
@ -43,5 +43,5 @@
when: docker_api_version is version('1.25', '>=')
- fail: msg="Too old Docker API version to run all docker_container_copy_into tests!"
- ansible.builtin.fail: msg="Too old Docker API version to run all docker_container_copy_into tests!"
when: not(docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

View File

@ -4,4 +4,4 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: "Loading tasks from {{ test_name }}"
include_tasks: "{{ test_name }}"
ansible.builtin.include_tasks: "{{ test_name }}"

View File

@ -4,16 +4,16 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cname: "{{ cname_prefix ~ '-c' }}"
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cnames: "{{ cnames + [cname] }}"
# Create container
- name: Create container
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command:
- /bin/sh
@ -31,7 +31,7 @@
# Do tests
- name: Copy content without mode
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -40,7 +40,7 @@
ignore_errors: true
- name: Check results
assert:
ansible.builtin.assert:
that:
- result is failed
- |-
@ -51,7 +51,7 @@
######################### Copy
- name: Copy content (check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -63,7 +63,7 @@
register: result_1
- name: Copy content (check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -75,7 +75,7 @@
register: result_1_diff
- name: Copy content (check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -85,7 +85,7 @@
register: result_2
- name: Copy content (idempotent, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -97,7 +97,7 @@
register: result_3
- name: Copy content (idempotent, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -109,7 +109,7 @@
register: result_3_diff
- name: Copy content (idempotent)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -119,7 +119,7 @@
register: result_4
- name: Copy content (idempotent, check mode, base 64)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: "{{ 'Content 1\n' | b64encode }}"
content_is_b64: true
@ -131,7 +131,7 @@
register: result_3b64
- name: Copy content (idempotent, check mode, base 64, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: "{{ 'Content 1\n' | b64encode }}"
content_is_b64: true
@ -143,7 +143,7 @@
register: result_3b64_diff
- name: Copy content (idempotent, base 64)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: "{{ 'Content 1\n' | b64encode }}"
content_is_b64: true
@ -153,7 +153,7 @@
register: result_4b64
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -165,7 +165,7 @@
register: result_5
- name: Copy content (force, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -178,7 +178,7 @@
register: result_6
- name: Copy content (force, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -191,7 +191,7 @@
register: result_6_diff
- name: Copy content (force)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -202,7 +202,7 @@
register: result_7
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -214,7 +214,7 @@
register: result_8
- name: Copy content (force=false, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Some other content
@ -229,7 +229,7 @@
register: result_9
- name: Copy content (force=false, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Some other content
@ -244,7 +244,7 @@
register: result_9_diff
- name: Copy content (force=false)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Some other content
@ -257,7 +257,7 @@
register: result_10
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -269,7 +269,7 @@
register: result_11
- name: Copy content (octal mode, mode_parse=modern)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -283,7 +283,7 @@
register: result_12
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -295,7 +295,7 @@
register: result_13
- name: Copy content (octal mode, mode_parse=legacy)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -309,7 +309,7 @@
register: result_14
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -321,7 +321,7 @@
register: result_15
- name: Copy content (string mode, mode_parse=legacy)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -333,7 +333,7 @@
register: result_16
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -345,7 +345,7 @@
register: result_17
- name: Copy content (string mode, mode_parse=octal_string_only)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -357,7 +357,7 @@
register: result_18
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -369,7 +369,7 @@
register: result_19
- name: Restore state for next tasks
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -380,7 +380,7 @@
group_id: 0
- name: Check results
assert:
ansible.builtin.assert:
that:
- result_1 is changed
- "'diff' not in result_1"
@ -444,7 +444,7 @@
######################### Follow link - idempotence
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -456,7 +456,7 @@
register: result_0
- name: Copy content following link (check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -469,7 +469,7 @@
register: result_1
- name: Copy content following link (check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -482,7 +482,7 @@
register: result_1_diff
- name: Copy content following link
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -493,7 +493,7 @@
register: result_2
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -506,7 +506,7 @@
register: result_3
- name: Copy content following link (force, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -520,7 +520,7 @@
register: result_4
- name: Copy content following link (force, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -534,7 +534,7 @@
register: result_4_diff
- name: Copy content following link (force)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -546,7 +546,7 @@
register: result_5
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -559,7 +559,7 @@
register: result_6
- name: Check results
assert:
ansible.builtin.assert:
that:
- result_0.stdout | b64decode == 'Content 1\n'
- result_0.stderr == "4 777 symbolic link 0 0 '/lnk' -> 'file'"
@ -593,7 +593,7 @@
######################### Do not follow link - replace by file
- name: Copy content not following link (check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -606,7 +606,7 @@
register: result_1
- name: Copy content not following link (check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -619,7 +619,7 @@
register: result_1_diff
- name: Copy content not following link
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -630,7 +630,7 @@
register: result_2
- name: Copy content not following link (idempotent, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -642,7 +642,7 @@
register: result_3
- name: Copy content not following link (idempotent, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -654,7 +654,7 @@
register: result_3_diff
- name: Copy content not following link (idempotent)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -664,7 +664,7 @@
register: result_4
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -676,7 +676,7 @@
register: result_5
- name: Copy content not following link (force, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -689,7 +689,7 @@
register: result_6
- name: Copy content not following link (force, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -702,7 +702,7 @@
register: result_6_diff
- name: Copy content not following link (force)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -713,7 +713,7 @@
register: result_7
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -725,7 +725,7 @@
register: result_8
- name: Check results
assert:
ansible.builtin.assert:
that:
- result_1 is changed
- result_1.container_path == '/lnk'
@ -763,7 +763,7 @@
######################### Replace directory by file
- name: Copy content to replace directory (check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -776,7 +776,7 @@
register: result_1
- name: Copy content to replace directory (check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -789,7 +789,7 @@
register: result_1_diff
- name: Copy content to replace directory (check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -800,7 +800,7 @@
register: result_2
- name: Copy content to replace directory (idempotent, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -812,7 +812,7 @@
register: result_3
- name: Copy content to replace directory (idempotent, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -824,7 +824,7 @@
register: result_3_diff
- name: Copy content to replace directory (idempotent)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -834,7 +834,7 @@
register: result_4
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -846,7 +846,7 @@
register: result_5
- name: Check results
assert:
ansible.builtin.assert:
that:
- result_1 is changed
- result_1.container_path == '/dir'
@ -872,7 +872,7 @@
######################### Modify
- name: Copy content (changed, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |-
Content 2
@ -885,7 +885,7 @@
register: result_1
- name: Copy content (changed, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |-
Content 2
@ -898,7 +898,7 @@
register: result_1_diff
- name: Copy content (changed)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |-
Content 2
@ -909,7 +909,7 @@
register: result_2
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -921,7 +921,7 @@
register: result_3
- name: Check results
assert:
ansible.builtin.assert:
that:
- result_1 is changed
- "'diff' not in result_1"
@ -937,7 +937,7 @@
######################### Change mode
- name: Copy content (mode changed, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |-
Content 2
@ -950,7 +950,7 @@
register: result_1
- name: Copy content (mode changed, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |-
Content 2
@ -963,7 +963,7 @@
register: result_1_diff
- name: Copy content (mode changed)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |-
Content 2
@ -974,7 +974,7 @@
register: result_2
- name: Copy content (idempotent, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |-
Content 2
@ -987,7 +987,7 @@
register: result_3
- name: Copy content (idempotent, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |-
Content 2
@ -1000,7 +1000,7 @@
register: result_3_diff
- name: Copy content (idempotent)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |-
Content 2
@ -1011,7 +1011,7 @@
register: result_4
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -1023,7 +1023,7 @@
register: result_5
- name: Check results
assert:
ansible.builtin.assert:
that:
- result_1 is changed
- "'diff' not in result_1"
@ -1047,7 +1047,7 @@
######################### Change owner and group
- name: Copy content (owner/group changed, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |-
Content 2
@ -1062,7 +1062,7 @@
register: result_1
- name: Copy content (owner/group changed, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |-
Content 2
@ -1077,7 +1077,7 @@
register: result_1_diff
- name: Copy content (owner/group changed)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |-
Content 2
@ -1090,7 +1090,7 @@
register: result_2
- name: Copy content (idempotent, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |-
Content 2
@ -1105,7 +1105,7 @@
register: result_3
- name: Copy content (idempotent, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |-
Content 2
@ -1120,7 +1120,7 @@
register: result_3_diff
- name: Copy content (idempotent)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |-
Content 2
@ -1133,7 +1133,7 @@
register: result_4
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -1145,7 +1145,7 @@
register: result_5
- name: Copy content (owner/group changed again, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |-
Content 2
@ -1160,7 +1160,7 @@
register: result_6
- name: Copy content (owner/group changed again, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |-
Content 2
@ -1175,7 +1175,7 @@
register: result_6_diff
- name: Copy content (owner/group changed again)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |-
Content 2
@ -1188,7 +1188,7 @@
register: result_7
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -1200,7 +1200,7 @@
register: result_8
- name: Check results
assert:
ansible.builtin.assert:
that:
- result_1 is changed
- "'diff' not in result_1"
@ -1234,13 +1234,13 @@
######################### Operate with stopped container
- name: Stop container
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: stopped
stop_timeout: 1
- name: Copy content (stopped container, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -1254,7 +1254,7 @@
register: result_1
- name: Copy content (stopped container, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -1268,7 +1268,7 @@
register: result_1_diff
- name: Copy content (stopped container)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -1280,7 +1280,7 @@
register: result_2
- name: Copy content (stopped container, idempotent, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -1294,7 +1294,7 @@
register: result_3
- name: Copy content (stopped container, idempotent, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -1308,7 +1308,7 @@
register: result_3_diff
- name: Copy content (stopped container, idempotent)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -1320,7 +1320,7 @@
register: result_4
- name: Copy content (stopped container, no owner/group provided, should fail)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
content: |
Content 1
@ -1331,12 +1331,12 @@
ignore_errors: true
- name: Start container
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: started
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -1348,7 +1348,7 @@
register: result_6
- name: Check results
assert:
ansible.builtin.assert:
that:
- result_1 is changed
- "'diff' not in result_1"
@ -1375,7 +1375,7 @@
# Cleanup
- name: Remove container
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true

View File

@ -4,16 +4,16 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cname: "{{ cname_prefix ~ '-f' }}"
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cnames: "{{ cnames + [cname] }}"
# Create container
- name: Create container
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command:
- /bin/sh
@ -30,14 +30,14 @@
# Create files
- name: Create file 1
copy:
ansible.builtin.copy:
dest: '{{ remote_tmp_dir }}/file_1'
content: |
Content 1
mode: "0644"
- name: Create file 2
copy:
ansible.builtin.copy:
dest: '{{ remote_tmp_dir }}/file_2'
content: |-
Content 2
@ -45,7 +45,7 @@
mode: "0644"
- name: Create link 1
file:
ansible.builtin.file:
dest: '{{ remote_tmp_dir }}/link_1'
state: link
src: file_1
@ -53,7 +53,7 @@
mode: "0644"
- name: Create link 2
file:
ansible.builtin.file:
dest: '{{ remote_tmp_dir }}/link_2'
state: link
src: dead
@ -67,7 +67,7 @@
######################### Copy
- name: Copy file (check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/file'
@ -76,7 +76,7 @@
register: result_1
- name: Copy file (check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/file'
@ -85,14 +85,14 @@
register: result_1_diff
- name: Copy file (check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/file'
register: result_2
- name: Copy file (idempotent, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/file'
@ -101,7 +101,7 @@
register: result_3
- name: Copy file (idempotent, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/file'
@ -110,14 +110,14 @@
register: result_3_diff
- name: Copy file (idempotent)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/file'
register: result_4
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -129,7 +129,7 @@
register: result_5
- name: Copy file (force, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/file'
@ -139,7 +139,7 @@
register: result_6
- name: Copy file (force, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/file'
@ -149,7 +149,7 @@
register: result_6_diff
- name: Copy file (force)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/file'
@ -157,7 +157,7 @@
register: result_7
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -169,7 +169,7 @@
register: result_8
- name: Copy file (force=false, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_2'
container_path: '/file'
@ -183,7 +183,7 @@
register: result_9
- name: Copy file (force=false, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_2'
container_path: '/file'
@ -197,7 +197,7 @@
register: result_9_diff
- name: Copy file (force=false)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_2'
container_path: '/file'
@ -209,7 +209,7 @@
register: result_10
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -221,7 +221,7 @@
register: result_11
- name: Check results
assert:
ansible.builtin.assert:
that:
- result_1 is changed
- "'diff' not in result_1"
@ -265,7 +265,7 @@
######################### Follow link - idempotence
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -277,7 +277,7 @@
register: result_0
- name: Copy file following link (check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/lnk'
@ -287,7 +287,7 @@
register: result_1
- name: Copy file following link (check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/lnk'
@ -297,7 +297,7 @@
register: result_1_diff
- name: Copy file following link
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/lnk'
@ -305,7 +305,7 @@
register: result_2
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -318,7 +318,7 @@
register: result_3
- name: Copy file following link (force, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/lnk'
@ -329,7 +329,7 @@
register: result_4
- name: Copy file following link (force, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/lnk'
@ -340,7 +340,7 @@
register: result_4_diff
- name: Copy file following link (force)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/lnk'
@ -349,7 +349,7 @@
register: result_5
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -362,7 +362,7 @@
register: result_6
- name: Check results
assert:
ansible.builtin.assert:
that:
- result_0.stdout | b64decode == 'Content 1\n'
- result_0.stderr == "4 777 symbolic link 0 0 '/lnk' -> 'file'"
@ -396,7 +396,7 @@
######################### Do not follow link - replace by file
- name: Copy file not following link (check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/lnk'
@ -406,7 +406,7 @@
register: result_1
- name: Copy file not following link (check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/lnk'
@ -416,7 +416,7 @@
register: result_1_diff
- name: Copy file not following link
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/lnk'
@ -424,7 +424,7 @@
register: result_2
- name: Copy file not following link (idempotent, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/lnk'
@ -433,7 +433,7 @@
register: result_3
- name: Copy file not following link (idempotent, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/lnk'
@ -442,14 +442,14 @@
register: result_3_diff
- name: Copy file not following link (idempotent)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/lnk'
register: result_4
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -461,7 +461,7 @@
register: result_5
- name: Copy file not following link (force, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/lnk'
@ -471,7 +471,7 @@
register: result_6
- name: Copy file not following link (force, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/lnk'
@ -481,7 +481,7 @@
register: result_6_diff
- name: Copy file not following link (force)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/lnk'
@ -489,7 +489,7 @@
register: result_7
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -501,7 +501,7 @@
register: result_8
- name: Check results
assert:
ansible.builtin.assert:
that:
- result_1 is changed
- result_1.container_path == '/lnk'
@ -539,7 +539,7 @@
######################### Replace directory by file
- name: Copy file to replace directory (check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/dir'
@ -549,7 +549,7 @@
register: result_1
- name: Copy file to replace directory (check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/dir'
@ -559,7 +559,7 @@
register: result_1_diff
- name: Copy file to replace directory (check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/dir'
@ -567,7 +567,7 @@
register: result_2
- name: Copy file to replace directory (idempotent, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/dir'
@ -576,7 +576,7 @@
register: result_3
- name: Copy file to replace directory (idempotent, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/dir'
@ -585,14 +585,14 @@
register: result_3_diff
- name: Copy file to replace directory (idempotent)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/dir'
register: result_4
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -604,7 +604,7 @@
register: result_5
- name: Check results
assert:
ansible.builtin.assert:
that:
- result_1 is changed
- result_1.container_path == '/dir'
@ -630,7 +630,7 @@
######################### Modify
- name: Copy file (changed, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_2'
container_path: '/file'
@ -639,7 +639,7 @@
register: result_1
- name: Copy file (changed, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_2'
container_path: '/file'
@ -648,14 +648,14 @@
register: result_1_diff
- name: Copy file (changed)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_2'
container_path: '/file'
register: result_2
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -667,7 +667,7 @@
register: result_3
- name: Check results
assert:
ansible.builtin.assert:
that:
- result_1 is changed
- "'diff' not in result_1"
@ -683,7 +683,7 @@
######################### Change mode
- name: Copy file (mode changed, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_2'
container_path: '/file'
@ -694,7 +694,7 @@
register: result_1
- name: Copy file (mode changed, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_2'
container_path: '/file'
@ -705,7 +705,7 @@
register: result_1_diff
- name: Copy file (mode changed)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_2'
container_path: '/file'
@ -714,7 +714,7 @@
register: result_2
- name: Copy file (idempotent, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_2'
container_path: '/file'
@ -725,7 +725,7 @@
register: result_3
- name: Copy file (idempotent, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_2'
container_path: '/file'
@ -736,7 +736,7 @@
register: result_3_diff
- name: Copy file (idempotent)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_2'
container_path: '/file'
@ -745,7 +745,7 @@
register: result_4
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -757,7 +757,7 @@
register: result_5
- name: Check results
assert:
ansible.builtin.assert:
that:
- result_1 is changed
- "'diff' not in result_1"
@ -781,7 +781,7 @@
######################### Change owner and group
- name: Copy file (owner/group changed, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_2'
container_path: '/file'
@ -794,7 +794,7 @@
register: result_1
- name: Copy file (owner/group changed, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_2'
container_path: '/file'
@ -807,7 +807,7 @@
register: result_1_diff
- name: Copy file (owner/group changed)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_2'
container_path: '/file'
@ -818,7 +818,7 @@
register: result_2
- name: Copy file (idempotent, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_2'
container_path: '/file'
@ -831,7 +831,7 @@
register: result_3
- name: Copy file (idempotent, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_2'
container_path: '/file'
@ -844,7 +844,7 @@
register: result_3_diff
- name: Copy file (idempotent)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_2'
container_path: '/file'
@ -855,7 +855,7 @@
register: result_4
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -867,7 +867,7 @@
register: result_5
- name: Copy file (owner/group changed again, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_2'
container_path: '/file'
@ -880,7 +880,7 @@
register: result_6
- name: Copy file (owner/group changed again, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_2'
container_path: '/file'
@ -893,7 +893,7 @@
register: result_6_diff
- name: Copy file (owner/group changed again)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_2'
container_path: '/file'
@ -904,7 +904,7 @@
register: result_7
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -916,7 +916,7 @@
register: result_8
- name: Check results
assert:
ansible.builtin.assert:
that:
- result_1 is changed
- "'diff' not in result_1"
@ -950,13 +950,13 @@
######################### Operate with stopped container
- name: Stop container
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: stopped
stop_timeout: 1
- name: Copy file (stopped container, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/file'
@ -969,7 +969,7 @@
register: result_1
- name: Copy file (stopped container, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/file'
@ -982,7 +982,7 @@
register: result_1_diff
- name: Copy file (stopped container)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/file'
@ -993,7 +993,7 @@
register: result_2
- name: Copy file (stopped container, idempotent, check mode)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/file'
@ -1006,7 +1006,7 @@
register: result_3
- name: Copy file (stopped container, idempotent, check mode, diff)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/file'
@ -1019,7 +1019,7 @@
register: result_3_diff
- name: Copy file (stopped container, idempotent)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/file'
@ -1030,7 +1030,7 @@
register: result_4
- name: Copy file (stopped container, no owner/group provided, should fail)
docker_container_copy_into:
community.docker.docker_container_copy_into:
container: '{{ cname }}'
path: '{{ remote_tmp_dir }}/file_1'
container_path: '/file'
@ -1040,12 +1040,12 @@
ignore_errors: true
- name: Start container
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: started
- name: Dump file
docker_container_exec:
community.docker.docker_container_exec:
container: '{{ cname }}'
argv:
- /bin/sh
@ -1057,7 +1057,7 @@
register: result_6
- name: Check results
assert:
ansible.builtin.assert:
that:
- result_1 is changed
- "'diff' not in result_1"
@ -1084,7 +1084,7 @@
# Cleanup
- name: Remove container
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true

View File

@ -10,29 +10,29 @@
- block:
- name: Create random container name
set_fact:
ansible.builtin.set_fact:
cname: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
- name: Make sure container is not there
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
- name: Execute in a non-present container
docker_container_exec:
community.docker.docker_container_exec:
container: "{{ cname }}"
command: "/bin/bash -c 'ls -a'"
register: result
ignore_errors: true
- assert:
- ansible.builtin.assert:
that:
- result is failed
- "'Could not find container' in result.msg"
- name: Make sure container exists
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
@ -40,12 +40,12 @@
force_kill: true
- name: Execute in a present container (command)
docker_container_exec:
community.docker.docker_container_exec:
container: "{{ cname }}"
command: "/bin/sh -c 'ls -a'"
register: result_cmd
- assert:
- ansible.builtin.assert:
that:
- result_cmd.rc == 0
- "'stdout' in result_cmd"
@ -54,7 +54,7 @@
- "'stderr_lines' in result_cmd"
- name: Execute in a present container (argv)
docker_container_exec:
community.docker.docker_container_exec:
container: "{{ cname }}"
argv:
- /bin/sh
@ -62,7 +62,7 @@
- ls -a
register: result_argv
- assert:
- ansible.builtin.assert:
that:
- result_argv.rc == 0
- "'stdout' in result_argv"
@ -72,7 +72,7 @@
- result_cmd.stdout == result_argv.stdout
- name: Execute in a present container (cat without stdin)
docker_container_exec:
community.docker.docker_container_exec:
container: "{{ cname }}"
argv:
- /bin/sh
@ -80,7 +80,7 @@
- cat
register: result
- assert:
- ansible.builtin.assert:
that:
- result.rc == 0
- result.stdout == ''
@ -89,7 +89,7 @@
- result.stderr_lines == []
- name: Execute in a present container (cat with stdin)
docker_container_exec:
community.docker.docker_container_exec:
container: "{{ cname }}"
argv:
- /bin/sh
@ -99,7 +99,7 @@
strip_empty_ends: false
register: result
- assert:
- ansible.builtin.assert:
that:
- result.rc == 0
- result.stdout == 'Hello world!\n'
@ -108,7 +108,7 @@
- result.stderr_lines == []
- name: Execute in a present container (cat with stdin, no newline)
docker_container_exec:
community.docker.docker_container_exec:
container: "{{ cname }}"
argv:
- /bin/sh
@ -119,7 +119,7 @@
strip_empty_ends: false
register: result
- assert:
- ansible.builtin.assert:
that:
- result.rc == 0
- result.stdout == 'Hello world!'
@ -128,7 +128,7 @@
- result.stderr_lines == []
- name: Execute in a present container (cat with stdin, newline but stripping)
docker_container_exec:
community.docker.docker_container_exec:
container: "{{ cname }}"
argv:
- /bin/sh
@ -139,7 +139,7 @@
strip_empty_ends: true
register: result
- assert:
- ansible.builtin.assert:
that:
- result.rc == 0
- result.stdout == 'Hello world!'
@ -148,12 +148,12 @@
- result.stderr_lines == []
- name: Prepare long string
set_fact:
ansible.builtin.set_fact:
very_long_string: "{{ 'something long ' * 10000 }}"
very_long_string2: "{{ 'something else ' * 5000 }}"
- name: Execute in a present container (long stdin)
docker_container_exec:
community.docker.docker_container_exec:
container: "{{ cname }}"
argv:
- /bin/sh
@ -164,7 +164,7 @@
{{ very_long_string2 }}
register: result
- assert:
- ansible.builtin.assert:
that:
- result is changed
- result.rc == 0
@ -175,7 +175,7 @@
- "'exec_id' not in result"
- name: Execute in a present container (detached)
docker_container_exec:
community.docker.docker_container_exec:
container: "{{ cname }}"
argv:
- /bin/sh
@ -184,9 +184,9 @@
detach: true
register: result
- debug: var=result
- ansible.builtin.debug: var=result
- assert:
- ansible.builtin.assert:
that:
- result is changed
- "'rc' not in result"
@ -195,7 +195,7 @@
- result.exec_id is string
- name: Execute in a present container (environment variable)
docker_container_exec:
community.docker.docker_container_exec:
container: "{{ cname }}"
argv:
- /bin/sh
@ -207,7 +207,7 @@
baz
register: result
- assert:
- ansible.builtin.assert:
that:
- result.rc == 0
- result.stdout == 'bar\nbaz'
@ -216,7 +216,7 @@
- result.stderr_lines == ['bar baz']
- name: Check result of detach test
docker_container_exec:
community.docker.docker_container_exec:
container: "{{ cname }}"
argv:
- /bin/sh
@ -225,7 +225,7 @@
strip_empty_ends: false
register: result
- assert:
- ansible.builtin.assert:
that:
- result.rc == 0
- result.stdout == 'Detach worked.\n'
@ -235,12 +235,12 @@
always:
- name: Cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
when: docker_api_version is version('1.25', '>=')
- fail: msg="Too old docker / docker-py version to run docker_container_exec tests!"
- ansible.builtin.fail: msg="Too old docker / docker-py version to run docker_container_exec tests!"
when: not(docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

View File

@ -10,28 +10,28 @@
- block:
- name: Create random container name
set_fact:
ansible.builtin.set_fact:
cname: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
- name: Make sure container is not there
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
- name: Inspect a non-present container
docker_container_info:
community.docker.docker_container_info:
name: "{{ cname }}"
register: result
- assert:
- ansible.builtin.assert:
that:
- "not result.exists"
- "'container' in result"
- "result.container is none"
- name: Make sure container exists
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
@ -39,46 +39,46 @@
force_kill: true
- name: Inspect a present container
docker_container_info:
community.docker.docker_container_info:
name: "{{ cname }}"
register: result
- name: Dump docker_container_info result
debug: var=result
ansible.builtin.debug: var=result
- name: "Comparison: use 'docker inspect'"
command: docker inspect "{{ cname }}"
ansible.builtin.command: docker inspect "{{ cname }}"
register: docker_inspect
ignore_errors: true
- block:
- set_fact:
- ansible.builtin.set_fact:
docker_inspect_result: "{{ docker_inspect.stdout | from_json }}"
- name: Dump docker inspect result
debug: var=docker_inspect_result
ansible.builtin.debug: var=docker_inspect_result
when: docker_inspect is not failed
- assert:
- ansible.builtin.assert:
that:
- result.exists
- "'container' in result"
- "result.container is truthy"
- assert:
- ansible.builtin.assert:
that:
- "result.container == docker_inspect_result[0]"
when: docker_inspect is not failed
- assert:
- ansible.builtin.assert:
that:
- "'is too new. Maximum supported API version is' in docker_inspect.stderr"
when: docker_inspect is failed
always:
- name: Cleanup
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
when: docker_api_version is version('1.25', '>=')
- fail: msg="Too old docker / docker-py version to run docker_container_info tests!"
- ansible.builtin.fail: msg="Too old docker / docker-py version to run docker_container_info tests!"
when: not(docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

View File

@ -10,16 +10,16 @@
# Create random name prefix (for containers, networks, ...)
- name: Create random container name prefix
set_fact:
ansible.builtin.set_fact:
cname_prefix: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
cnames: []
- debug:
- ansible.builtin.debug:
msg: "Using container name prefix {{ cname_prefix }}"
# Run the tests
- block:
- include_tasks: run-test.yml
- ansible.builtin.include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"
loop_control:
@ -27,7 +27,7 @@
always:
- name: "Make sure all containers are removed"
docker_container:
community.docker.docker_container:
name: "{{ item }}"
state: absent
force_kill: true
@ -36,5 +36,5 @@
when: docker_api_version is version('1.25', '>=')
- fail: msg="Too old docker / docker-py version to run all docker_container tests!"
- ansible.builtin.fail: msg="Too old docker / docker-py version to run all docker_container tests!"
when: not(docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

View File

@ -4,4 +4,4 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: "Loading tasks from {{ test_name }}"
include_tasks: "{{ test_name }}"
ansible.builtin.include_tasks: "{{ test_name }}"

View File

@ -4,10 +4,10 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cname: "{{ cname_prefix ~ '-hi' }}"
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
cnames: "{{ cnames + [cname] }}"
- name: Get current context
@ -15,7 +15,7 @@
only_current: true
register: docker_current_context
- assert:
- ansible.builtin.assert:
that:
- docker_current_context is not changed
# Some of the following tests will not be true on all machines, but they should be in CI:
@ -34,7 +34,7 @@
group/community.docker.docker: "{{ docker_current_context.contexts[0].config }}"
block:
- name: Create container
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -42,14 +42,14 @@
register: create_1
- name: Create container (idempotent)
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: present
register: create_2
- assert:
- ansible.builtin.assert:
that:
- create_1 is changed
- create_2 is not changed
@ -59,24 +59,24 @@
cmd: docker inspect {{ cname }}
register: result
- assert:
- ansible.builtin.assert:
that:
- (result.stdout | from_json) | length == 1
- (result.stdout | from_json)[0].State.Status == "created"
- name: Start container
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: started
register: start_1
- name: Start container (idempotent)
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: started
register: start_2
- assert:
- ansible.builtin.assert:
that:
- start_1 is changed
- start_2 is not changed
@ -86,26 +86,26 @@
cmd: docker inspect {{ cname }}
register: result
- assert:
- ansible.builtin.assert:
that:
- (result.stdout | from_json) | length == 1
- (result.stdout | from_json)[0].State.Status == "running"
- name: Remove container
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
register: remove_1
- name: Remove container (idempotent)
docker_container:
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
register: remove_2
- assert:
- ansible.builtin.assert:
that:
- remove_1 is changed
- remove_2 is not changed
@ -116,6 +116,6 @@
register: result
failed_when: result.rc != 1
- assert:
- ansible.builtin.assert:
that:
- (result.stdout | from_json) | length == 0

View File

@ -12,7 +12,7 @@
register: docker_contexts
- name: Ensure that there are at least two contexts
assert:
ansible.builtin.assert:
that:
- docker_contexts.contexts | length >= 2
@ -21,7 +21,7 @@
name: podman
register: docker_podman_context
- assert:
- ansible.builtin.assert:
that:
- docker_podman_context.contexts | length == 1
- docker_podman_context.contexts[0].name == 'podman'
@ -38,11 +38,11 @@
block:
- name: Get info on Podman host
docker_host_info:
community.docker.docker_host_info:
register: output
- name: Check for some Podman specific values
assert:
ansible.builtin.assert:
that:
- output.host_info.ProductLicense == 'Apache-2.0'
- >-

View File

@ -8,10 +8,10 @@
# and should not be used as examples of how to write Ansible roles #
####################################################################
- include_tasks: test_host_info.yml
- ansible.builtin.include_tasks: test_host_info.yml
when: docker_api_version is version('1.25', '>=')
- fail: msg="Too old docker / docker-py version to run docker_host_info tests!"
- ansible.builtin.fail: msg="Too old docker / docker-py version to run docker_host_info tests!"
when: not(docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)
- when: podman_cli_version is version('1.0.0', '>=')
@ -27,11 +27,11 @@
block:
- name: Get info on Podman host
docker_host_info:
community.docker.docker_host_info:
register: output
- name: Check for some Podman specific values
assert:
ansible.builtin.assert:
that:
- output.host_info.ProductLicense == 'Apache-2.0'
- >-

View File

@ -4,21 +4,21 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Create random container/volume name
set_fact:
ansible.builtin.set_fact:
cname: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
cname2: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
vname: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
- debug:
- ansible.builtin.debug:
msg: "Using container names '{{ cname }}' and '{{ cname2 }}', and volume name '{{ vname }}'"
- block:
- name: Get info on Docker host
docker_host_info:
community.docker.docker_host_info:
register: output
- name: assert reading docker host facts when docker is running
assert:
ansible.builtin.assert:
that:
- output.host_info.Name is string
- output.containers is not defined
@ -30,26 +30,26 @@
- block:
- name: Get info on Docker host with invalid api_version
docker_host_info:
community.docker.docker_host_info:
api_version: 1.999.999
register: output
ignore_errors: true
- name: assert can_talk_is_docker is false
assert:
ansible.builtin.assert:
that:
- output is failed
- output.can_talk_to_docker is false
- block:
- name: Get info on Docker host with invalid docker_host
docker_host_info:
community.docker.docker_host_info:
docker_host: tcp://127.0.0.1:80
register: output
ignore_errors: true
- name: assert can_talk_is_docker is false
assert:
ansible.builtin.assert:
that:
- output is failed
- output.can_talk_to_docker is false
@ -59,7 +59,7 @@
# * image list is non-empty because the image of the container is there;
# * network list is always non-empty (default networks).
- name: Create running container
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
@ -70,7 +70,7 @@
register: container_output
- name: Create running container
docker_container:
community.docker.docker_container:
image: "{{ docker_test_image_alpine }}"
name: "{{ cname2 }}"
labels:
@ -79,27 +79,27 @@
state: stopped
register: container2_output
- assert:
- ansible.builtin.assert:
that:
- container_output is changed
- container2_output is changed
- name: Create a volume
docker_volume:
community.docker.docker_volume:
name: "{{ vname }}"
register: volume_output
- assert:
- ansible.builtin.assert:
that:
- volume_output is changed
- name: Get info on Docker host and list containers
docker_host_info:
community.docker.docker_host_info:
containers: true
register: output
- name: assert reading docker host facts when docker is running and list containers
assert:
ansible.builtin.assert:
that:
- 'output.host_info.Name is string'
- 'output.networks is not defined'
@ -110,18 +110,18 @@
- 'output.containers[0].ImageID is not defined'
- name: Get info on Docker host and list containers matching filters (single label)
docker_host_info:
community.docker.docker_host_info:
containers: true
containers_filters:
label: key1=value1
register: output
- name: assert container is returned when filters are matched (single label)
assert:
ansible.builtin.assert:
that: "output.containers | length == 1"
- name: Get info on Docker host and list containers matching filters (multiple labels)
docker_host_info:
community.docker.docker_host_info:
containers: true
containers_filters:
label:
@ -130,11 +130,11 @@
register: output
- name: assert container is returned when filters are matched (multiple labels)
assert:
ansible.builtin.assert:
that: "output.containers | length == 1"
- name: Get info on Docker host and do not list containers which do not match filters
docker_host_info:
community.docker.docker_host_info:
containers: true
containers_filters:
label:
@ -144,11 +144,11 @@
register: output
- name: assert no container is returned when filters are not matched
assert:
ansible.builtin.assert:
that: "output.containers | length == 0"
- name: Get info on Docker host and list containers matching filters (single label, not all containers)
docker_host_info:
community.docker.docker_host_info:
containers: true
containers_all: false
containers_filters:
@ -156,7 +156,7 @@
register: output
- name: Get info on Docker host and list containers matching filters (single label, all containers)
docker_host_info:
community.docker.docker_host_info:
containers: true
containers_all: true
containers_filters:
@ -164,19 +164,19 @@
register: output_all
- name: assert one resp. two container is returned
assert:
ansible.builtin.assert:
that:
- "output.containers | length == 1"
- "output_all.containers | length == 2"
- name: Get info on Docker host and list containers with verbose output
docker_host_info:
community.docker.docker_host_info:
containers: true
verbose_output: true
register: output
- name: assert reading docker host facts when docker is running and list containers with verbose output
assert:
ansible.builtin.assert:
that:
- 'output.host_info.Name is string'
- 'output.networks is not defined'
@ -187,12 +187,12 @@
- 'output.containers[0].ImageID is string'
- name: Get info on Docker host and list images
docker_host_info:
community.docker.docker_host_info:
images: true
register: output
- name: assert reading docker host facts when docker is running and list images
assert:
ansible.builtin.assert:
that:
- 'output.host_info.Name is string'
- 'output.containers is not defined'
@ -203,13 +203,13 @@
- 'output.disk_usage is not defined'
- name: Get info on Docker host and list images with verbose output
docker_host_info:
community.docker.docker_host_info:
images: true
verbose_output: true
register: output
- name: assert reading docker host facts when docker is running and list images with verbose output
assert:
ansible.builtin.assert:
that:
- 'output.host_info.Name is string'
- 'output.containers is not defined'
@ -220,12 +220,12 @@
- 'output.disk_usage is not defined'
- name: Get info on Docker host and list networks
docker_host_info:
community.docker.docker_host_info:
networks: true
register: output
- name: assert reading docker host facts when docker is running and list networks
assert:
ansible.builtin.assert:
that:
- 'output.host_info.Name is string'
- 'output.containers is not defined'
@ -236,13 +236,13 @@
- 'output.disk_usage is not defined'
- name: Get info on Docker host and list networks with verbose output
docker_host_info:
community.docker.docker_host_info:
networks: true
verbose_output: true
register: output
- name: assert reading docker host facts when docker is running and list networks with verbose output
assert:
ansible.builtin.assert:
that:
- 'output.host_info.Name is string'
- 'output.containers is not defined'
@ -253,12 +253,12 @@
- 'output.disk_usage is not defined'
- name: Get info on Docker host and list volumes
docker_host_info:
community.docker.docker_host_info:
volumes: true
register: output
- name: assert reading docker host facts when docker is running and list volumes
assert:
ansible.builtin.assert:
that:
- 'output.host_info.Name is string'
- 'output.containers is not defined'
@ -269,13 +269,13 @@
- 'output.disk_usage is not defined'
- name: Get info on Docker host and list volumes with verbose output
docker_host_info:
community.docker.docker_host_info:
volumes: true
verbose_output: true
register: output
- name: assert reading docker host facts when docker is running and list volumes with verbose output
assert:
ansible.builtin.assert:
that:
- 'output.host_info.Name is string'
- 'output.containers is not defined'
@ -286,12 +286,12 @@
- 'output.disk_usage is not defined'
- name: Get info on Docker host and get disk usage
docker_host_info:
community.docker.docker_host_info:
disk_usage: true
register: output
- name: assert reading docker host facts when docker is running and get disk usage
assert:
ansible.builtin.assert:
that:
- 'output.host_info.Name is string'
- 'output.containers is not defined'
@ -304,13 +304,13 @@
- 'output.disk_usage.Volumes is not defined'
- name: Get info on Docker host and get disk usage with verbose output
docker_host_info:
community.docker.docker_host_info:
disk_usage: true
verbose_output: true
register: output
- name: assert reading docker host facts when docker is running and get disk usage with verbose output
assert:
ansible.builtin.assert:
that:
- 'output.host_info.Name is string'
- 'output.containers is not defined'
@ -323,7 +323,7 @@
- 'output.disk_usage.Volumes is sequence'
- name: Get info on Docker host, disk usage and get all lists together
docker_host_info:
community.docker.docker_host_info:
volumes: true
containers: true
networks: true
@ -332,7 +332,7 @@
register: output
- name: assert reading docker host facts when docker is running, disk usage and get lists together
assert:
ansible.builtin.assert:
that:
- 'output.host_info.Name is string'
- 'output.containers[0].Image is string'
@ -349,7 +349,7 @@
- 'output.disk_usage.Volumes is not defined'
- name: Get info on Docker host, disk usage and get all lists together with verbose output
docker_host_info:
community.docker.docker_host_info:
volumes: true
containers: true
networks: true
@ -359,7 +359,7 @@
register: output
- name: assert reading docker host facts when docker is running and get disk usage with verbose output
assert:
ansible.builtin.assert:
that:
- 'output.host_info.Name is string'
- 'output.containers[0].Image is string'
@ -377,7 +377,7 @@
always:
- name: Delete containers
docker_container:
community.docker.docker_container:
name: "{{ item }}"
state: absent
force_kill: true
@ -386,6 +386,6 @@
- "{{ cname2 }}"
- name: Delete volume
docker_volume:
community.docker.docker_volume:
name: "{{ vname }}"
state: absent

View File

@ -9,5 +9,5 @@
####################################################################
- when: ansible_facts.distribution ~ ansible_facts.distribution_major_version not in ['CentOS6', 'RedHat6']
include_tasks:
ansible.builtin.include_tasks:
file: test.yml

View File

@ -4,4 +4,4 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: "Loading tasks from {{ test_name }}"
include_tasks: "{{ test_name }}"
ansible.builtin.include_tasks: "{{ test_name }}"

View File

@ -4,23 +4,23 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Create random name prefix
set_fact:
ansible.builtin.set_fact:
name_prefix: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
- name: Create image and container list
set_fact:
ansible.builtin.set_fact:
inames: []
cnames: []
- debug:
- ansible.builtin.debug:
msg: "Using name prefix {{ name_prefix }}"
- name: Create files directory
file:
ansible.builtin.file:
path: '{{ remote_tmp_dir }}/files'
state: directory
- name: Template files
template:
ansible.builtin.template:
src: '{{ item }}'
dest: '{{ remote_tmp_dir }}/files/{{ item }}'
loop:
@ -31,7 +31,7 @@
- StagedDockerfile
- block:
- include_tasks: run-test.yml
- ansible.builtin.include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"
loop_control:
@ -39,12 +39,12 @@
always:
- name: "Make sure all images are removed"
docker_image:
community.docker.docker_image:
name: "{{ item }}"
state: absent
with_items: "{{ inames }}"
- name: "Make sure all containers are removed"
docker_container:
community.docker.docker_container:
name: "{{ item }}"
state: absent
force_kill: true
@ -52,5 +52,5 @@
when: docker_api_version is version('1.25', '>=')
- fail: msg="Too old docker / docker-py version to run docker_image tests!"
- ansible.builtin.fail: msg="Too old docker / docker-py version to run docker_image tests!"
when: not(docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

View File

@ -8,24 +8,24 @@
####################################################################
- name: Make sure image is not there
docker_image:
community.docker.docker_image:
name: "{{ docker_test_image_hello_world }}"
state: absent
force_absent: true
register: absent_1
- name: Make sure image is not there (idempotency)
docker_image:
community.docker.docker_image:
name: "{{ docker_test_image_hello_world }}"
state: absent
register: absent_2
- assert:
- ansible.builtin.assert:
that:
- absent_2 is not changed
- name: Make sure image is there
docker_image:
community.docker.docker_image:
name: "{{ docker_test_image_hello_world }}"
state: present
source: pull
@ -34,7 +34,7 @@
register: present_1
- name: Make sure image is there (idempotent)
docker_image:
community.docker.docker_image:
name: "{{ docker_test_image_hello_world }}"
state: present
source: pull
@ -42,32 +42,32 @@
platform: amd64
register: present_2
- assert:
- ansible.builtin.assert:
that:
- present_1 is changed
- present_2 is not changed
- name: Make sure tag is not there
docker_image:
community.docker.docker_image:
name: "{{ docker_test_image_hello_world_base }}:alias"
state: absent
- name: Tag image with alias
docker_image:
community.docker.docker_image:
source: local
name: "{{ docker_test_image_hello_world }}"
repository: "{{ docker_test_image_hello_world_base }}:alias"
register: tag_1
- name: Tag image with alias (idempotent)
docker_image:
community.docker.docker_image:
source: local
name: "{{ docker_test_image_hello_world }}"
repository: "{{ docker_test_image_hello_world_base }}:alias"
register: tag_2
- name: Tag image with alias (force, still idempotent)
docker_image:
community.docker.docker_image:
source: local
name: "{{ docker_test_image_hello_world }}"
repository: "{{ docker_test_image_hello_world_base }}:alias"
@ -75,13 +75,13 @@
register: tag_3
- name: Tag image with ID instead of name
docker_image:
community.docker.docker_image:
source: local
name: "{{ present_1.image.Id }}"
repository: "{{ docker_test_image_hello_world_base }}:alias"
register: tag_4
- assert:
- ansible.builtin.assert:
that:
- tag_1 is changed
- tag_2 is not changed
@ -89,12 +89,12 @@
- tag_4 is not changed
- name: Cleanup alias tag
docker_image:
community.docker.docker_image:
name: "{{ docker_test_image_hello_world_base }}:alias"
state: absent
- name: Tag image with ID instead of name (use ID for repository, must fail)
docker_image:
community.docker.docker_image:
source: local
name: "{{ docker_test_image_hello_world }}"
repository: "{{ present_1.image.Id }}"
@ -102,7 +102,7 @@
ignore_errors: true
- name: Push image with ID (must fail)
docker_image:
community.docker.docker_image:
source: local
name: "{{ present_1.image.Id }}"
push: true
@ -110,7 +110,7 @@
ignore_errors: true
- name: Pull image ID (must fail)
docker_image:
community.docker.docker_image:
source: pull
name: "{{ present_1.image.Id }}"
force_source: true
@ -118,7 +118,7 @@
ignore_errors: true
- name: Build image ID (must fail)
docker_image:
community.docker.docker_image:
source: build
name: "{{ present_1.image.Id }}"
build:
@ -127,7 +127,7 @@
register: fail_4
ignore_errors: true
- assert:
- ansible.builtin.assert:
that:
- fail_1 is failed
- "'`repository` must not be an image ID' in fail_1.msg"

View File

@ -4,16 +4,16 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Registering image name
set_fact:
ansible.builtin.set_fact:
iname: "{{ name_prefix ~ '-options' }}"
- name: Determining pushed image names
set_fact:
ansible.builtin.set_fact:
hello_world_image_base: "{{ registry_address | default('localhost') }}/test/hello-world"
test_image_base: "{{ registry_address | default('localhost') }}/test/{{ iname }}"
- name: Registering image name
set_fact:
ansible.builtin.set_fact:
inames: "{{ inames + [iname, test_image_base ~ ':latest', test_image_base ~ ':other', hello_world_image_base ~ ':latest', hello_world_image_base ~ ':newtag', hello_world_image_base ~ ':newtag2'] }}"
####################################################################
@ -24,18 +24,18 @@
when: registry_address is defined
block:
- name: Make sure image is not there
docker_image:
community.docker.docker_image:
name: "{{ hello_world_image_base }}:latest"
state: absent
force_absent: true
- name: Make sure we have {{ docker_test_image_hello_world }}
docker_image:
community.docker.docker_image:
name: "{{ docker_test_image_hello_world }}"
source: pull
- name: Push image to test registry
docker_image:
community.docker.docker_image:
name: "{{ docker_test_image_hello_world }}"
repository: "{{ hello_world_image_base }}:latest"
push: true
@ -43,7 +43,7 @@
register: push_1
- name: Push image to test registry (idempotent)
docker_image:
community.docker.docker_image:
name: "{{ docker_test_image_hello_world }}"
repository: "{{ hello_world_image_base }}:latest"
push: true
@ -51,7 +51,7 @@
register: push_2
- name: Push image to test registry (force, still idempotent)
docker_image:
community.docker.docker_image:
name: "{{ docker_test_image_hello_world }}"
repository: "{{ hello_world_image_base }}:latest"
push: true
@ -59,48 +59,48 @@
force_tag: true
register: push_3
- assert:
- ansible.builtin.assert:
that:
- push_1 is changed
- push_2 is not changed
- push_3 is not changed
- name: Get facts of local image
docker_image_info:
community.docker.docker_image_info:
name: "{{ hello_world_image_base }}:latest"
register: facts_1
- name: Make sure image is not there
docker_image:
community.docker.docker_image:
name: "{{ hello_world_image_base }}:latest"
state: absent
force_absent: true
- name: Get facts of local image (absent)
docker_image_info:
community.docker.docker_image_info:
name: "{{ hello_world_image_base }}:latest"
register: facts_2
- name: Pull image from test registry
docker_image:
community.docker.docker_image:
name: "{{ hello_world_image_base }}:latest"
state: present
source: pull
register: pull_1
- name: Pull image from test registry (idempotency)
docker_image:
community.docker.docker_image:
name: "{{ hello_world_image_base }}:latest"
state: present
source: pull
register: pull_2
- name: Get facts of local image (present)
docker_image_info:
community.docker.docker_image_info:
name: "{{ hello_world_image_base }}:latest"
register: facts_3
- assert:
- ansible.builtin.assert:
that:
- pull_1 is changed
- pull_2 is not changed
@ -109,7 +109,7 @@
- facts_3.images | length == 1
- name: Pull image from test registry (with digest)
docker_image:
community.docker.docker_image:
name: "{{ hello_world_image_base }}@{{ facts_3.images[0].RepoDigests[0] | regex_replace('.*@', '') }}"
state: present
source: pull
@ -117,19 +117,19 @@
register: pull_digest
- name: Make sure that changed is still false
assert:
ansible.builtin.assert:
that:
- pull_digest is not changed
- name: Tag different image with new tag
docker_image:
community.docker.docker_image:
name: "{{ docker_test_image_alpine_different }}"
repository: "{{ hello_world_image_base }}:newtag"
push: false
source: pull
- name: Push different image with new tag
docker_image:
community.docker.docker_image:
name: "{{ hello_world_image_base }}"
repository: "{{ hello_world_image_base }}"
tag: newtag
@ -138,7 +138,7 @@
register: push_1_different
- name: Push different image with new tag (idempotent)
docker_image:
community.docker.docker_image:
name: "{{ hello_world_image_base }}"
repository: "{{ hello_world_image_base }}"
tag: newtag
@ -146,20 +146,20 @@
source: local
register: push_2_different
- assert:
- ansible.builtin.assert:
that:
- push_1_different is changed
- push_2_different is not changed
- name: Tag same image with new tag
docker_image:
community.docker.docker_image:
name: "{{ docker_test_image_alpine_different }}"
repository: "{{ hello_world_image_base }}:newtag2"
push: false
source: pull
- name: Push same image with new tag
docker_image:
community.docker.docker_image:
name: "{{ hello_world_image_base }}"
repository: "{{ hello_world_image_base }}"
tag: newtag2
@ -168,7 +168,7 @@
register: push_1_same
- name: Push same image with new tag (idempotent)
docker_image:
community.docker.docker_image:
name: "{{ hello_world_image_base }}"
repository: "{{ hello_world_image_base }}"
tag: newtag2
@ -176,7 +176,7 @@
source: local
register: push_2_same
- assert:
- ansible.builtin.assert:
that:
# NOTE: This should be:
# - push_1_same is changed
@ -202,13 +202,13 @@
####################################################################
- name: Make sure image is not there
docker_image:
community.docker.docker_image:
name: "{{ test_image_base }}:latest"
state: absent
force_absent: true
- name: repository
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
build:
path: "{{ remote_tmp_dir }}/files"
@ -218,28 +218,28 @@
register: repository_1
- name: repository (idempotent)
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
repository: "{{ test_image_base }}"
source: local
register: repository_2
- name: repository, tag with ID
docker_image:
community.docker.docker_image:
name: "{{ repository_1.image.Id }}"
repository: "{{ test_image_base }}:other"
source: local
register: repository_3
- name: repository, tag with ID (idempotent)
docker_image:
community.docker.docker_image:
name: "{{ repository_1.image.Id }}"
repository: "{{ test_image_base }}:other"
source: local
force_tag: true
register: repository_4
- assert:
- ansible.builtin.assert:
that:
- repository_1 is changed
- repository_2 is not changed
@ -247,16 +247,16 @@
- repository_4 is not changed
- name: Get facts of image
docker_image_info:
community.docker.docker_image_info:
name: "{{ test_image_base }}:latest"
register: facts_1
- name: cleanup
docker_image:
community.docker.docker_image:
name: "{{ test_image_base }}:latest"
state: absent
force_absent: true
- assert:
- ansible.builtin.assert:
that:
- facts_1.images | length == 1

View File

@ -4,13 +4,13 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Registering image name
set_fact:
ansible.builtin.set_fact:
iname: "{{ name_prefix ~ '-options' }}"
iname_1: "{{ name_prefix ~ '-options-1' }}"
hello_world_alt: "{{ name_prefix }}-hello-world-alt:v1.2.3-foo"
- name: Registering image name
set_fact:
ansible.builtin.set_fact:
inames: "{{ inames + [iname, iname_1, hello_world_alt] }}"
####################################################################
@ -18,13 +18,13 @@
####################################################################
- name: cleanup
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
state: absent
force_absent: true
- name: buildargs
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
build:
path: "{{ remote_tmp_dir }}/files"
@ -40,7 +40,7 @@
ignore_errors: true
- name: buildargs (idempotency)
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
build:
path: "{{ remote_tmp_dir }}/files"
@ -56,12 +56,12 @@
ignore_errors: true
- name: cleanup
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
state: absent
force_absent: true
- assert:
- ansible.builtin.assert:
that:
- buildargs_1 is changed
- buildargs_2 is not failed and buildargs_2 is not changed
@ -71,7 +71,7 @@
####################################################################
- name: container_limits (Failed due to min memory limit)
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
build:
path: "{{ remote_tmp_dir }}/files"
@ -83,7 +83,7 @@
register: container_limits_1
- name: container_limits
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
build:
path: "{{ remote_tmp_dir }}/files"
@ -95,12 +95,12 @@
register: container_limits_2
- name: cleanup
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
state: absent
force_absent: true
- assert:
- ansible.builtin.assert:
that:
# It *sometimes* happens that the first task does not fail.
# For now, we work around this by
@ -116,7 +116,7 @@
####################################################################
- name: dockerfile
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
build:
path: "{{ remote_tmp_dir }}/files"
@ -126,12 +126,12 @@
register: dockerfile_1
- name: cleanup
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
state: absent
force_absent: true
- assert:
- ansible.builtin.assert:
that:
- dockerfile_1 is changed
- "('FROM ' ~ docker_test_image_alpine) in dockerfile_1.stdout"
@ -142,13 +142,13 @@
####################################################################
- name: cleanup
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
state: absent
force_absent: true
- name: build.platform
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
build:
path: "{{ remote_tmp_dir }}/files"
@ -159,7 +159,7 @@
ignore_errors: true
- name: build.platform (idempotency)
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
build:
path: "{{ remote_tmp_dir }}/files"
@ -170,12 +170,12 @@
ignore_errors: true
- name: cleanup
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
state: absent
force_absent: true
- assert:
- ansible.builtin.assert:
that:
- platform_1 is changed
- platform_2 is not failed and platform_2 is not changed
@ -185,7 +185,7 @@
####################################################################
- name: Build an image
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
build:
path: "{{ remote_tmp_dir }}/files"
@ -193,7 +193,7 @@
source: build
- name: force (changed)
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
build:
path: "{{ remote_tmp_dir }}/files"
@ -204,7 +204,7 @@
register: force_1
- name: force (unchanged)
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
build:
path: "{{ remote_tmp_dir }}/files"
@ -215,12 +215,12 @@
register: force_2
- name: cleanup
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
state: absent
force_absent: true
- assert:
- ansible.builtin.assert:
that:
- force_1 is changed
- force_2 is not changed
@ -230,103 +230,103 @@
####################################################################
- name: Archive image
docker_image:
community.docker.docker_image:
name: "{{ docker_test_image_hello_world }}"
archive_path: "{{ remote_tmp_dir }}/image.tar"
source: pull
register: archive_image
- assert:
- ansible.builtin.assert:
that:
- archive_image is changed
- name: Copy archive because we will mutate it but other tests need the original
copy:
ansible.builtin.copy:
remote_src: true
src: "{{ remote_tmp_dir }}/image.tar"
dest: "{{ remote_tmp_dir }}/image_mutated.tar"
- name: Archive image again (idempotent)
docker_image:
community.docker.docker_image:
name: "{{ docker_test_image_hello_world }}"
archive_path: "{{ remote_tmp_dir }}/image_mutated.tar"
source: local
register: archive_image_2
- assert:
- ansible.builtin.assert:
that:
- archive_image_2 is not changed
- name: Archive image 3rd time, should overwrite due to different id
docker_image:
community.docker.docker_image:
name: "{{ docker_test_image_alpine_different }}"
archive_path: "{{ remote_tmp_dir }}/image_mutated.tar"
source: pull
register: archive_image_3
- assert:
- ansible.builtin.assert:
that:
- archive_image_3 is changed
- name: Reset archive
copy:
ansible.builtin.copy:
remote_src: true
src: "{{ remote_tmp_dir }}/image.tar"
dest: "{{ remote_tmp_dir }}/image_mutated.tar"
- name: Tag image with different name
docker_image:
community.docker.docker_image:
name: "{{ docker_test_image_hello_world }}"
repository: "{{ hello_world_alt }}"
source: local
- name: Archive image 4th time, should overwrite due to different name even when ID is same
docker_image:
community.docker.docker_image:
name: "{{ hello_world_alt }}"
# Tagged as docker_test_image_hello_world but has same hash/id (before this task overwrites it)
archive_path: "{{ remote_tmp_dir }}/image_mutated.tar"
source: local
register: archive_image_4
- assert:
- ansible.builtin.assert:
that:
- archive_image_4 is changed
# This is the test that needs the original, non-mutated archive
- name: Archive image by ID
docker_image:
community.docker.docker_image:
name: "{{ archive_image.image.Id }}"
archive_path: "{{ remote_tmp_dir }}/image_id.tar"
source: local
register: archive_image_id
- name: Create invalid archive
copy:
ansible.builtin.copy:
dest: "{{ remote_tmp_dir }}/image-invalid.tar"
content: "this is not a valid image"
- name: remove image
docker_image:
community.docker.docker_image:
name: "{{ docker_test_image_hello_world }}"
state: absent
force_absent: true
- name: load image (changed)
docker_image:
community.docker.docker_image:
name: "{{ docker_test_image_hello_world }}"
load_path: "{{ remote_tmp_dir }}/image.tar"
source: load
register: load_image
- name: load image (idempotency)
docker_image:
community.docker.docker_image:
name: "{{ docker_test_image_hello_world }}"
load_path: "{{ remote_tmp_dir }}/image.tar"
source: load
register: load_image_1
- name: load image (wrong name)
docker_image:
community.docker.docker_image:
name: foo:bar
load_path: "{{ remote_tmp_dir }}/image.tar"
source: load
@ -334,7 +334,7 @@
ignore_errors: true
- name: load image (invalid image)
docker_image:
community.docker.docker_image:
name: foo:bar
load_path: "{{ remote_tmp_dir }}/image-invalid.tar"
source: load
@ -342,13 +342,13 @@
ignore_errors: true
- name: load image (ID, idempotency)
docker_image:
community.docker.docker_image:
name: "{{ archive_image.image.Id }}"
load_path: "{{ remote_tmp_dir }}/image_id.tar"
source: load
register: load_image_4
- assert:
- ansible.builtin.assert:
that:
- load_image is changed
- archive_image['image']['Id'] == load_image['image']['Id']
@ -365,7 +365,7 @@
####################################################################
- name: Build image
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
build:
path: "{{ remote_tmp_dir }}/files"
@ -374,7 +374,7 @@
register: path_1
- name: Build image (idempotency)
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
build:
path: "{{ remote_tmp_dir }}/files"
@ -383,12 +383,12 @@
register: path_2
- name: cleanup
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
state: absent
force_absent: true
- assert:
- ansible.builtin.assert:
that:
- path_1 is changed
- path_2 is not changed
@ -398,7 +398,7 @@
####################################################################
- name: Build multi-stage image
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
build:
path: "{{ remote_tmp_dir }}/files"
@ -409,12 +409,12 @@
register: dockerfile_2
- name: cleanup
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
state: absent
force_absent: true
- assert:
- ansible.builtin.assert:
that:
- dockerfile_2 is changed
- dockerfile_2.image.Config.WorkingDir == '/first'
@ -424,7 +424,7 @@
####################################################################
- name: Build image with custom etc_hosts
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
build:
path: "{{ remote_tmp_dir }}/files"
@ -436,12 +436,12 @@
register: path_1
- name: cleanup
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
state: absent
force_absent: true
- assert:
- ansible.builtin.assert:
that:
- path_1 is changed
@ -450,7 +450,7 @@
####################################################################
- name: Build image with custom shm_size
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
build:
path: "{{ remote_tmp_dir }}/files"
@ -461,12 +461,12 @@
register: path_1
- name: cleanup
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
state: absent
force_absent: true
- assert:
- ansible.builtin.assert:
that:
- path_1 is changed
@ -475,7 +475,7 @@
####################################################################
- name: Build image with labels
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
build:
path: "{{ remote_tmp_dir }}/files"
@ -488,16 +488,16 @@
register: labels_1
- name: cleanup
docker_image:
community.docker.docker_image:
name: "{{ iname }}"
state: absent
force_absent: true
- name: Show image information
debug:
ansible.builtin.debug:
var: labels_1.image
- assert:
- ansible.builtin.assert:
that:
- labels_1 is changed
- labels_1.image.Config.Labels.FOO == 'BAR'

View File

@ -9,5 +9,5 @@
####################################################################
- when: ansible_facts.distribution ~ ansible_facts.distribution_major_version not in ['CentOS6', 'RedHat6']
include_tasks:
ansible.builtin.include_tasks:
file: test.yml

View File

@ -4,4 +4,4 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: "Loading tasks from {{ test_name }}"
include_tasks: "{{ test_name }}"
ansible.builtin.include_tasks: "{{ test_name }}"

View File

@ -4,23 +4,23 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Create random name prefix
set_fact:
ansible.builtin.set_fact:
name_prefix: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
- name: Create image and container list
set_fact:
ansible.builtin.set_fact:
inames: []
cnames: []
- debug:
- ansible.builtin.debug:
msg: "Using name prefix {{ name_prefix }}"
- name: Create files directory
file:
ansible.builtin.file:
path: '{{ remote_tmp_dir }}/files'
state: directory
- name: Template files
template:
ansible.builtin.template:
src: '{{ item }}'
dest: '{{ remote_tmp_dir }}/files/{{ item }}'
loop:
@ -31,22 +31,22 @@
- SecretsDockerfile
- StagedDockerfile
- debug:
- ansible.builtin.debug:
msg: "Has buildx plugin: {{ docker_has_buildx }}"
- block:
- name: Determine plugin versions
command: docker info -f '{{ "{{" }}json .ClientInfo.Plugins{{ "}}" }}'
ansible.builtin.command: docker info -f '{{ "{{" }}json .ClientInfo.Plugins{{ "}}" }}'
register: plugin_versions
- name: Determine buildx plugin version
set_fact:
ansible.builtin.set_fact:
buildx_version: >-
{{
(plugin_versions.stdout | from_json | selectattr('Name', 'eq', 'buildx') | map(attribute='Version') | first).lstrip('v')
}}
- include_tasks: run-test.yml
- ansible.builtin.include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"
loop_control:
@ -54,12 +54,12 @@
always:
- name: "Make sure all images are removed"
docker_image:
community.docker.docker_image:
name: "{{ item }}"
state: absent
with_items: "{{ inames }}"
- name: "Make sure all containers are removed"
docker_container:
community.docker.docker_container:
name: "{{ item }}"
state: absent
force_kill: true
@ -67,5 +67,5 @@
when: docker_api_version is version('1.25', '>=') and docker_cli_version is version('19.03', '>=') and docker_has_buildx
- fail: msg="Too old docker / docker-py version to run docker_image tests!"
- ansible.builtin.fail: msg="Too old docker / docker-py version to run docker_image tests!"
when: not(docker_api_version is version('1.25', '>=') and docker_cli_version is version('19.03', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6) and docker_has_buildx

View File

@ -4,11 +4,11 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Registering image name
set_fact:
ansible.builtin.set_fact:
iname: "{{ name_prefix ~ '-options' }}"
- name: Registering image name
set_fact:
ansible.builtin.set_fact:
inames: "{{ inames + [iname] }}"
####################################################################
@ -16,11 +16,11 @@
####################################################################
- name: cleanup
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ iname }}"
- name: buildargs
docker_image_build:
community.docker.docker_image_build:
name: "{{ iname }}"
path: "{{ remote_tmp_dir }}/files"
dockerfile: "ArgsDockerfile"
@ -33,7 +33,7 @@
register: buildargs_1
- name: buildargs (idempotency)
docker_image_build:
community.docker.docker_image_build:
name: "{{ iname }}"
path: "{{ remote_tmp_dir }}/files"
dockerfile: "ArgsDockerfile"
@ -46,10 +46,10 @@
register: buildargs_2
- name: cleanup
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ iname }}"
- assert:
- ansible.builtin.assert:
that:
- buildargs_1 is changed
- buildargs_2 is not changed
@ -59,7 +59,7 @@
####################################################################
- name: dockerfile
docker_image_build:
community.docker.docker_image_build:
name: "{{ iname }}"
path: "{{ remote_tmp_dir }}/files"
dockerfile: "MyDockerfile"
@ -67,10 +67,10 @@
register: dockerfile_1
- name: cleanup
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ iname }}"
- assert:
- ansible.builtin.assert:
that:
- dockerfile_1 is changed
- "('FROM ' ~ docker_test_image_alpine) in dockerfile_1.stderr"
@ -81,11 +81,11 @@
####################################################################
- name: cleanup
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ iname }}"
- name: platform
docker_image_build:
community.docker.docker_image_build:
name: "{{ iname }}"
path: "{{ remote_tmp_dir }}/files"
platform: linux
@ -93,7 +93,7 @@
register: platform_1
- name: platform (idempotency)
docker_image_build:
community.docker.docker_image_build:
name: "{{ iname }}"
path: "{{ remote_tmp_dir }}/files"
platform: linux
@ -101,10 +101,10 @@
register: platform_2
- name: cleanup
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ iname }}"
- assert:
- ansible.builtin.assert:
that:
- platform_1 is changed
- platform_2 is not changed
@ -114,7 +114,7 @@
####################################################################
- name: Build multi-stage image
docker_image_build:
community.docker.docker_image_build:
name: "{{ iname }}"
path: "{{ remote_tmp_dir }}/files"
dockerfile: "StagedDockerfile"
@ -123,10 +123,10 @@
register: dockerfile_2
- name: cleanup
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ iname }}"
- assert:
- ansible.builtin.assert:
that:
- dockerfile_2 is changed
- dockerfile_2.image.Config.WorkingDir == '/first'
@ -136,7 +136,7 @@
####################################################################
- name: Build image with custom etc_hosts
docker_image_build:
community.docker.docker_image_build:
name: "{{ iname }}"
path: "{{ remote_tmp_dir }}/files"
dockerfile: "EtcHostsDockerfile"
@ -146,10 +146,10 @@
register: path_1
- name: cleanup
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ iname }}"
- assert:
- ansible.builtin.assert:
that:
- path_1 is changed
@ -158,7 +158,7 @@
####################################################################
- name: Build image with custom shm_size
docker_image_build:
community.docker.docker_image_build:
name: "{{ iname }}"
path: "{{ remote_tmp_dir }}/files"
dockerfile: "MyDockerfile"
@ -167,10 +167,10 @@
register: path_1
- name: cleanup
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ iname }}"
- assert:
- ansible.builtin.assert:
that:
- path_1 is changed
@ -179,7 +179,7 @@
####################################################################
- name: Build image with labels
docker_image_build:
community.docker.docker_image_build:
name: "{{ iname }}"
path: "{{ remote_tmp_dir }}/files"
dockerfile: "MyDockerfile"
@ -190,14 +190,14 @@
register: labels_1
- name: cleanup
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ iname }}"
- name: Show image information
debug:
ansible.builtin.debug:
var: labels_1.image
- assert:
- ansible.builtin.assert:
that:
- labels_1 is changed
- labels_1.image.Config.Labels.FOO == 'BAR'
@ -208,13 +208,13 @@
####################################################################
- name: Generate secret
set_fact:
ansible.builtin.set_fact:
docker_image_build_secret_value: this is my secret {{ '%0x' % ((2**32) | random) }}
- when: buildx_version is version('0.6.0', '>=')
block:
- name: Build image with secrets via environment variables
docker_image_build:
community.docker.docker_image_build:
name: "{{ iname }}"
path: "{{ remote_tmp_dir }}/files"
dockerfile: "SecretsDockerfile"
@ -227,14 +227,14 @@
register: secrets_1
- name: cleanup
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ iname }}"
- name: Show image information
debug:
ansible.builtin.debug:
var: secrets_1.stderr_lines
- assert:
- ansible.builtin.assert:
that:
- secrets_1 is changed
- (docker_image_build_secret_value | b64encode) in secrets_1.stderr
@ -246,16 +246,16 @@
- when: buildx_version is version('0.13.0', '>=')
block:
- name: Make sure the image is not there
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ iname }}"
- name: Make sure the image tarball is not there
file:
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/container.tar"
state: absent
- name: Build image with outputs
docker_image_build:
community.docker.docker_image_build:
name: "{{ iname }}"
path: "{{ remote_tmp_dir }}/files"
dockerfile: "Dockerfile"
@ -269,24 +269,24 @@
- when: outputs_1 is not failed
block:
- name: cleanup (should be changed)
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ iname }}"
register: outputs_1_cleanup
- name: Gather information on tarball
stat:
ansible.builtin.stat:
path: "{{ remote_tmp_dir }}/container.tar"
register: outputs_1_stat
- name: Show image information
debug:
ansible.builtin.debug:
var: outputs_1.image
- name: Show tarball information
debug:
ansible.builtin.debug:
var: outputs_1_stat.stat
- assert:
- ansible.builtin.assert:
that:
- outputs_1 is changed
- outputs_1.image | length > 0
@ -294,7 +294,7 @@
- outputs_1_stat.stat.exists
- when: outputs_1 is failed
assert:
ansible.builtin.assert:
that:
- >-
'ERROR: multiple outputs currently unsupported by the current BuildKit daemon' in outputs_1.stderr

View File

@ -9,5 +9,5 @@
####################################################################
- when: ansible_facts.distribution ~ ansible_facts.distribution_major_version not in ['CentOS6', 'RedHat6']
include_tasks:
ansible.builtin.include_tasks:
file: test.yml

View File

@ -4,4 +4,4 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: "Loading tasks from {{ test_name }}"
include_tasks: "{{ test_name }}"
ansible.builtin.include_tasks: "{{ test_name }}"

View File

@ -4,18 +4,18 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Create random name prefix
set_fact:
ansible.builtin.set_fact:
name_prefix: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
- name: Create image and container list
set_fact:
ansible.builtin.set_fact:
inames: []
cnames: []
- debug:
- ansible.builtin.debug:
msg: "Using name prefix {{ name_prefix }}"
- block:
- include_tasks: run-test.yml
- ansible.builtin.include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"
loop_control:
@ -23,11 +23,11 @@
always:
- name: "Make sure all images are removed"
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ item }}"
with_items: "{{ inames }}"
- name: "Make sure all containers are removed"
docker_container:
community.docker.docker_container:
name: "{{ item }}"
state: absent
force_kill: true
@ -35,5 +35,5 @@
when: docker_api_version is version('1.25', '>=')
- fail: msg="Too old docker / docker-py version to run docker_image tests!"
- ansible.builtin.fail: msg="Too old docker / docker-py version to run docker_image tests!"
when: not(docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

View File

@ -3,14 +3,14 @@
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- set_fact:
- ansible.builtin.set_fact:
image_names:
- "{{ docker_test_image_hello_world }}"
- "{{ docker_test_image_simple_1 }}"
- "{{ docker_test_image_simple_2 }}"
- name: Make sure images are there
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ item }}"
register: images
loop: "{{ image_names }}"
@ -37,7 +37,7 @@
block:
- name: Create archives
docker_image_export:
community.docker.docker_image_export:
names: "{{ item.images }}"
path: "{{ remote_tmp_dir }}/{{ item.file }}"
loop: "{{ image_tasks }}"
@ -46,14 +46,14 @@
register: result
- name: Extract manifest.json files
command: tar xvf "{{ remote_tmp_dir }}/{{ item.file }}" manifest.json --to-stdout
ansible.builtin.command: tar xvf "{{ remote_tmp_dir }}/{{ item.file }}" manifest.json --to-stdout
loop: "{{ image_tasks }}"
loop_control:
label: "{{ item.file }}"
register: manifests
- name: Do basic tests
assert:
ansible.builtin.assert:
that:
- item.0.images | length == item.1 | length
- item.1 | unique | length == item.2 | length

View File

@ -10,45 +10,45 @@
- block:
- name: Make sure image is not there
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ docker_test_image_alpine_different }}"
- name: Inspect a non-available image
docker_image_info:
community.docker.docker_image_info:
name: "{{ docker_test_image_alpine_different }}"
register: result
- assert:
- ansible.builtin.assert:
that:
- "result.images|length == 0"
- name: Make sure images are there
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ item }}"
loop:
- "{{ docker_test_image_hello_world }}"
- "{{ docker_test_image_alpine }}"
- name: Inspect an available image
docker_image_info:
community.docker.docker_image_info:
name: "{{ docker_test_image_hello_world }}"
register: result
- assert:
- ansible.builtin.assert:
that:
- "result.images|length == 1"
- "docker_test_image_hello_world in result.images[0].RepoTags"
- name: Inspect multiple images
docker_image_info:
community.docker.docker_image_info:
name:
- "{{ docker_test_image_hello_world }}"
- "{{ docker_test_image_alpine }}"
register: result
- debug: var=result
- ansible.builtin.debug: var=result
- assert:
- ansible.builtin.assert:
that:
- "result.images|length == 2"
- "docker_test_image_hello_world in result.images[0].RepoTags"
@ -56,5 +56,5 @@
when: docker_api_version is version('1.25', '>=')
- fail: msg="Too old docker / docker-py version to run docker_image_info tests!"
- ansible.builtin.fail: msg="Too old docker / docker-py version to run docker_image_info tests!"
when: not(docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

View File

@ -9,5 +9,5 @@
####################################################################
- when: ansible_facts.distribution ~ ansible_facts.distribution_major_version not in ['CentOS6', 'RedHat6']
include_tasks:
ansible.builtin.include_tasks:
file: test.yml

View File

@ -4,4 +4,4 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: "Loading tasks from {{ test_name }}"
include_tasks: "{{ test_name }}"
ansible.builtin.include_tasks: "{{ test_name }}"

View File

@ -4,18 +4,18 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Create random name prefix
set_fact:
ansible.builtin.set_fact:
name_prefix: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
- name: Create image and container list
set_fact:
ansible.builtin.set_fact:
inames: []
cnames: []
- debug:
- ansible.builtin.debug:
msg: "Using name prefix {{ name_prefix }}"
- block:
- include_tasks: run-test.yml
- ansible.builtin.include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"
loop_control:
@ -23,11 +23,11 @@
always:
- name: "Make sure all images are removed"
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ item }}"
with_items: "{{ inames }}"
- name: "Make sure all containers are removed"
docker_container:
community.docker.docker_container:
name: "{{ item }}"
state: absent
force_kill: true
@ -35,5 +35,5 @@
when: docker_api_version is version('1.25', '>=')
- fail: msg="Too old docker / docker-py version to run docker_image tests!"
- ansible.builtin.fail: msg="Too old docker / docker-py version to run docker_image tests!"
when: not(docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

View File

@ -3,25 +3,25 @@
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- set_fact:
- ansible.builtin.set_fact:
image_names:
- "{{ docker_test_image_hello_world }}"
- "{{ docker_test_image_simple_1 }}"
- "{{ docker_test_image_simple_2 }}"
- name: Make sure images are there
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ item }}"
register: images
loop: "{{ image_names }}"
- name: Compile list of all image names and IDs
set_fact:
ansible.builtin.set_fact:
image_ids: "{{ images.results | map(attribute='image') | map(attribute='Id') | list }}"
all_images: "{{ image_names + (images.results | map(attribute='image') | map(attribute='Id') | list) }}"
- name: Create archives
docker_image_export:
community.docker.docker_image_export:
names: "{{ item.images }}"
path: "{{ remote_tmp_dir }}/{{ item.file }}"
loop:
@ -44,7 +44,7 @@
# All images by IDs
- name: Remove all images
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ item }}"
force: true
loop: "{{ all_images }}"
@ -52,52 +52,52 @@
register: remove_all_images
- name: Prune all containers (if removing failed)
docker_prune:
community.docker.docker_prune:
containers: true
when: remove_all_images is failed
- name: Obtain all docker containers and images (if removing failed)
shell: docker ps -a ; docker images -a
ansible.builtin.shell: docker ps -a ; docker images -a
when: remove_all_images is failed
register: docker_container_image_list
- name: Show all docker containers and images (if removing failed)
debug:
ansible.builtin.debug:
var: docker_container_image_list.stdout_lines
when: remove_all_images is failed
- name: Remove all images (after pruning)
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ item }}"
force: true
loop: "{{ all_images }}"
when: remove_all_images is failed
- name: Load all images (IDs)
docker_image_load:
community.docker.docker_image_load:
path: "{{ remote_tmp_dir }}/archive-2.tar"
register: result
- name: Print loaded image names
debug:
ansible.builtin.debug:
var: result.image_names
- assert:
- ansible.builtin.assert:
that:
- result is changed
- result.image_names | sort == image_ids | sort
- result.image_names | length == result.images | length
- name: Load all images (IDs, should be same result)
docker_image_load:
community.docker.docker_image_load:
path: "{{ remote_tmp_dir }}/archive-2.tar"
register: result_2
- name: Print loaded image names
debug:
ansible.builtin.debug:
var: result_2.image_names
- assert:
- ansible.builtin.assert:
that:
- result_2 is changed
- result_2.image_names | sort == image_ids | sort
@ -106,24 +106,24 @@
# Mixed images and IDs
- name: Remove all images
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ item }}"
loop: "{{ all_images }}"
- name: Load all images (mixed images and IDs)
docker_image_load:
community.docker.docker_image_load:
path: "{{ remote_tmp_dir }}/archive-3.tar"
register: result
- name: Print loading log
debug:
ansible.builtin.debug:
var: result.stdout_lines
- name: Print loaded image names
debug:
ansible.builtin.debug:
var: result.image_names
- assert:
- ansible.builtin.assert:
that:
- result is changed
# For some reason, *sometimes* only the named image is found; in fact, in that case, the log only mentions that image and nothing else
@ -135,20 +135,20 @@
# Same image twice
- name: Remove all images
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ item }}"
loop: "{{ all_images }}"
- name: Load all images (same image twice)
docker_image_load:
community.docker.docker_image_load:
path: "{{ remote_tmp_dir }}/archive-4.tar"
register: result
- name: Print loaded image names
debug:
ansible.builtin.debug:
var: result.image_names
- assert:
- ansible.builtin.assert:
that:
- result is changed
- result.image_names | length == 1
@ -159,20 +159,20 @@
# Single image by ID
- name: Remove all images
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ item }}"
loop: "{{ all_images }}"
- name: Load all images (single image by ID)
docker_image_load:
community.docker.docker_image_load:
path: "{{ remote_tmp_dir }}/archive-5.tar"
register: result
- name: Print loaded image names
debug:
ansible.builtin.debug:
var: result.image_names
- assert:
- ansible.builtin.assert:
that:
- result is changed
- result.image_names | length == 1
@ -181,32 +181,32 @@
- result.images[0].Id == image_ids[0]
- name: Try to get image info by name
docker_image_info:
community.docker.docker_image_info:
name: "{{ image_names[0] }}"
register: result
- name: Make sure that image does not exist by name
assert:
ansible.builtin.assert:
that:
- result.images | length == 0
# All images by names
- name: Remove all images
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ item }}"
loop: "{{ all_images }}"
- name: Load all images (names)
docker_image_load:
community.docker.docker_image_load:
path: "{{ remote_tmp_dir }}/archive-1.tar"
register: result
- name: Print loaded image names
debug:
ansible.builtin.debug:
var: result.image_names
- assert:
- ansible.builtin.assert:
that:
- result.image_names | sort == image_names | sort
- result.image_names | length == result.images | length

View File

@ -9,5 +9,5 @@
####################################################################
- when: ansible_facts.distribution ~ ansible_facts.distribution_major_version not in ['CentOS6', 'RedHat6']
include_tasks:
ansible.builtin.include_tasks:
file: test.yml

View File

@ -4,4 +4,4 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: "Loading tasks from {{ test_name }}"
include_tasks: "{{ test_name }}"
ansible.builtin.include_tasks: "{{ test_name }}"

View File

@ -4,18 +4,18 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Create random name prefix
set_fact:
ansible.builtin.set_fact:
name_prefix: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
- name: Create image and container list
set_fact:
ansible.builtin.set_fact:
inames: []
cnames: []
- debug:
- ansible.builtin.debug:
msg: "Using name prefix {{ name_prefix }}"
- block:
- include_tasks: run-test.yml
- ansible.builtin.include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"
loop_control:
@ -23,11 +23,11 @@
always:
- name: "Make sure all images are removed"
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ item }}"
with_items: "{{ inames }}"
- name: "Make sure all containers are removed"
docker_container:
community.docker.docker_container:
name: "{{ item }}"
state: absent
force_kill: true
@ -35,5 +35,5 @@
when: docker_api_version is version('1.25', '>=')
- fail: msg="Too old docker / docker-py version to run docker_image tests!"
- ansible.builtin.fail: msg="Too old docker / docker-py version to run docker_image tests!"
when: not(docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

View File

@ -8,114 +8,114 @@
image_name: "{{ docker_test_image_simple_1 }}"
block:
- name: Make sure image is not there
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ image_name }}"
force: true
- name: Pull image (check mode)
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ image_name }}"
platform: amd64
register: present_1_check
check_mode: true
- debug:
- ansible.builtin.debug:
var: present_1_check.diff
- name: Pull image
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ image_name }}"
platform: amd64
register: present_1
- debug:
- ansible.builtin.debug:
var: present_1.diff
- name: Pull image (idempotent 1, check mode)
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ image_name }}"
platform: amd64
pull: always
register: present_2_check
check_mode: true
- debug:
- ansible.builtin.debug:
var: present_2_check.diff
- name: Pull image (idempotent 1)
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ image_name }}"
platform: amd64
pull: always
register: present_2
- debug:
- ansible.builtin.debug:
var: present_2.diff
- name: Pull image (change, check mode)
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ image_name }}"
platform: arm64
pull: always
register: present_3_check
check_mode: true
- debug:
- ansible.builtin.debug:
var: present_3_check.diff
- name: Pull image (change)
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ image_name }}"
platform: arm64
pull: always
register: present_3
- debug:
- ansible.builtin.debug:
var: present_3.diff
- name: Pull image (idempotent 2, check mode)
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ image_name }}"
platform: arm64
pull: not_present
register: present_4_check
check_mode: true
- debug:
- ansible.builtin.debug:
var: present_4_check.diff
- name: Pull image (idempotent 2)
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ image_name }}"
platform: arm64
pull: not_present
register: present_4
- debug:
- ansible.builtin.debug:
var: present_4.diff
- name: Pull image (change, check mode)
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ image_name }}"
platform: amd64
pull: not_present
register: present_5_check
check_mode: true
- debug:
- ansible.builtin.debug:
var: present_5_check.diff
- name: Pull image (change)
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ image_name }}"
platform: amd64
pull: not_present
register: present_5
- debug:
- ansible.builtin.debug:
var: present_5.diff
- assert:
- ansible.builtin.assert:
that:
- present_1_check is changed
- present_1_check.actions | length == 1
@ -169,24 +169,24 @@
always:
- name: cleanup
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ image_name }}"
force: true
- name: Pull image ID (must fail)
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ present_1.image.Id }}"
register: fail_1
ignore_errors: true
- name: Pull invalid tag (must fail)
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ docker_test_image_hello_world }}"
tag: foo/bar
register: fail_2
ignore_errors: true
- assert:
- ansible.builtin.assert:
that:
- fail_1 is failed
- >-

View File

@ -6,7 +6,7 @@
- name: Image ID pull tests
block:
- name: Make sure images are not there
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ item }}"
force: true
loop:
@ -14,26 +14,26 @@
- "sha256:{{ docker_test_image_digest_v2_image_id }}"
- name: Pull image 1
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ docker_test_image_digest_base }}@sha256:{{ docker_test_image_digest_v1 }}"
register: present_1
diff: true
- name: Pull image 1 (idempotent, do pull)
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ docker_test_image_digest_base }}@sha256:{{ docker_test_image_digest_v1 }}"
pull: always
register: present_2
diff: true
- name: Pull image 1 (idempotent, do not pull)
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ docker_test_image_digest_base }}@sha256:{{ docker_test_image_digest_v1 }}"
pull: not_present
register: present_3
diff: true
- assert:
- ansible.builtin.assert:
that:
- present_1 is changed
- present_1.actions | length == 1
@ -51,7 +51,7 @@
- present_3.diff.after.id == present_1.diff.after.id
- name: Pull image 2 (check mode)
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ docker_test_image_digest_base }}@sha256:{{ docker_test_image_digest_v2 }}"
pull: always
register: present_4
@ -59,13 +59,13 @@
check_mode: true
- name: Pull image 2
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ docker_test_image_digest_base }}@sha256:{{ docker_test_image_digest_v2 }}"
pull: always
register: present_5
diff: true
- assert:
- ansible.builtin.assert:
that:
- present_4 is changed
- present_4.actions | length == 1
@ -81,7 +81,7 @@
always:
- name: cleanup
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ item }}"
force: true
loop:

View File

@ -7,67 +7,67 @@
when: registry_address is defined
block:
- name: Registering image name
set_fact:
ansible.builtin.set_fact:
iname: "{{ name_prefix ~ '-options' }}"
- name: Determining pushed image names
set_fact:
ansible.builtin.set_fact:
hello_world_image_base: "{{ registry_address }}/test/hello-world"
- name: Registering image name
set_fact:
ansible.builtin.set_fact:
inames: "{{ inames + [iname, hello_world_image_base ~ ':latest'] }}"
- name: Make sure image is not there
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ hello_world_image_base }}:latest"
force: true
- name: Make sure we have {{ docker_test_image_hello_world }}
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ docker_test_image_hello_world }}"
diff: true
- name: Tag image
docker_image_tag:
community.docker.docker_image_tag:
name: "{{ docker_test_image_hello_world }}"
repository:
- "{{ hello_world_image_base }}:latest"
- name: Push image to test registry
docker_image_push:
community.docker.docker_image_push:
name: "{{ hello_world_image_base }}:latest"
- name: Get facts of local image
docker_image_info:
community.docker.docker_image_info:
name: "{{ hello_world_image_base }}:latest"
register: facts_1
- name: Make sure image is not there
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ hello_world_image_base }}:latest"
force: true
- name: Get facts of local image (not there)
docker_image_info:
community.docker.docker_image_info:
name: "{{ hello_world_image_base }}:latest"
register: facts_2
- name: Pull image from test registry (check mode)
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ hello_world_image_base }}:latest"
register: pull_1_check
diff: true
check_mode: true
- name: Pull image from test registry
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ hello_world_image_base }}:latest"
register: pull_1
diff: true
- name: Pull image from test registry (idempotency, not pulling, check mode)
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ hello_world_image_base }}:latest"
pull: not_present
register: pull_2_check
@ -75,14 +75,14 @@
check_mode: true
- name: Pull image from test registry (idempotency, not pulling)
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ hello_world_image_base }}:latest"
pull: not_present
register: pull_2
diff: true
- name: Pull image from test registry (idempotency, pulling, check mode)
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ hello_world_image_base }}:latest"
pull: always
register: pull_3_check
@ -90,18 +90,18 @@
check_mode: true
- name: Pull image from test registry (idempotency, pulling)
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ hello_world_image_base }}:latest"
pull: always
register: pull_3
diff: true
- name: Get facts of local image (present)
docker_image_info:
community.docker.docker_image_info:
name: "{{ hello_world_image_base }}:latest"
register: facts_3
- assert:
- ansible.builtin.assert:
that:
- pull_1_check is changed
- pull_1_check.diff.before.exists is false

View File

@ -9,5 +9,5 @@
####################################################################
- when: ansible_facts.distribution ~ ansible_facts.distribution_major_version not in ['CentOS6', 'RedHat6']
include_tasks:
ansible.builtin.include_tasks:
file: test.yml

View File

@ -4,4 +4,4 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: "Loading tasks from {{ test_name }}"
include_tasks: "{{ test_name }}"
ansible.builtin.include_tasks: "{{ test_name }}"

View File

@ -4,18 +4,18 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Create random name prefix
set_fact:
ansible.builtin.set_fact:
name_prefix: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
- name: Create image and container list
set_fact:
ansible.builtin.set_fact:
inames: []
cnames: []
- debug:
- ansible.builtin.debug:
msg: "Using name prefix {{ name_prefix }}"
- block:
- include_tasks: run-test.yml
- ansible.builtin.include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"
loop_control:
@ -23,11 +23,11 @@
always:
- name: "Make sure all images are removed"
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ item }}"
with_items: "{{ inames }}"
- name: "Make sure all containers are removed"
docker_container:
community.docker.docker_container:
name: "{{ item }}"
state: absent
force_kill: true
@ -35,5 +35,5 @@
when: docker_api_version is version('1.25', '>=')
- fail: msg="Too old docker / docker-py version to run docker_image tests!"
- ansible.builtin.fail: msg="Too old docker / docker-py version to run docker_image tests!"
when: not(docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

View File

@ -7,41 +7,41 @@
image_name: registry.example.com:5000/foo/bar:baz
block:
- name: Make sure image is not present
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ image_name }}"
- name: Push non-existing image (must fail)
docker_image_push:
community.docker.docker_image_push:
name: "{{ image_name }}"
register: fail_1
ignore_errors: true
- name: Push image ID (must fail)
docker_image_push:
community.docker.docker_image_push:
name: "sha256:{{ docker_test_image_digest_v1_image_id }}"
register: fail_2
ignore_errors: true
- name: Push image with digest (must fail)
docker_image_push:
community.docker.docker_image_push:
name: "{{ docker_test_image_digest_base }}@sha256:{{ docker_test_image_digest_v1 }}"
register: fail_3
ignore_errors: true
- name: Push invalid tag (must fail)
docker_image_push:
community.docker.docker_image_push:
name: "{{ docker_test_image_hello_world }}"
tag: foo/bar
register: fail_4
ignore_errors: true
- name: Push invalid tag 2 (must fail)
docker_image_push:
community.docker.docker_image_push:
name: "{{ docker_test_image_digest_base }}:foo bar"
register: fail_5
ignore_errors: true
- assert:
- ansible.builtin.assert:
that:
- fail_1 is failed
- >-

View File

@ -7,7 +7,7 @@
when: registry_address is defined
block:
- name: Pull images
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ item }}"
loop:
- "{{ docker_test_image_hello_world }}"
@ -15,44 +15,44 @@
register: pulled_images
- name: Determining pushed image names
set_fact:
ansible.builtin.set_fact:
image_name_base: "{{ registry_address }}/test/{{ name_prefix }}"
image_name_base2: "{{ registry_frontend2_address }}/test/{{ name_prefix }}"
image_tag: latest
- name: Registering image name
set_fact:
ansible.builtin.set_fact:
inames: "{{ inames + [image_name_base ~ ':' ~ image_tag, image_name_base2 ~ ':' ~ image_tag] }}"
- name: Tag first image
docker_image_tag:
community.docker.docker_image_tag:
name: "{{ docker_test_image_hello_world }}"
repository:
- "{{ image_name_base }}:{{ image_tag }}"
- "{{ image_name_base2 }}:{{ image_tag }}"
- name: Push first image
docker_image_push:
community.docker.docker_image_push:
name: "{{ image_name_base }}:{{ image_tag }}"
register: push_1
- name: Push first image (idempotent)
docker_image_push:
community.docker.docker_image_push:
name: "{{ image_name_base }}:{{ image_tag }}"
register: push_2
- name: Tag second image
docker_image_tag:
community.docker.docker_image_tag:
name: "{{ docker_test_image_alpine }}"
repository:
- "{{ image_name_base }}:{{ image_tag }}"
- name: Push second image with same name
docker_image_push:
community.docker.docker_image_push:
name: "{{ image_name_base }}:{{ image_tag }}"
register: push_3
- assert:
- ansible.builtin.assert:
that:
- push_1 is changed
- push_1.image.Id == pulled_images.results[0].image.Id
@ -64,19 +64,19 @@
- when: registry_frontend2_address != 'n/a'
block:
- name: Make sure we are logged out from registry
docker_login:
community.docker.docker_login:
registry_url: "{{ registry_frontend2_address }}"
username: testuser
password: hunter2
state: absent
- name: Push image (unauthenticated)
docker_image_push:
community.docker.docker_image_push:
name: "{{ image_name_base2 }}:{{ image_tag }}"
register: push_4
ignore_errors: true
- assert:
- ansible.builtin.assert:
that:
- push_4 is failed
- >-

View File

@ -10,11 +10,11 @@
- block:
- name: Pick image prefix
set_fact:
ansible.builtin.set_fact:
iname_prefix: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
- name: Define image names
set_fact:
ansible.builtin.set_fact:
image: "{{ docker_test_image_hello_world }}"
image_id: "{{ docker_test_image_hello_world_image_id }}"
image_names:
@ -23,40 +23,40 @@
- "{{ iname_prefix }}-tagged-1:bar"
- name: Remove image complete
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ image_id }}"
force: true
- name: Remove tagged images
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ item }}"
loop: "{{ image_names }}"
- name: Make sure image we work with is there
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ image }}"
register: pulled_image
diff: true
- name: Remove tagged image (not there, check mode)
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ iname_prefix }}-tagged-1:latest"
register: remove_1_check
check_mode: true
diff: true
- name: Remove tagged image (not there)
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ iname_prefix }}-tagged-1:latest"
register: remove_1
diff: true
- name: Inspect image
docker_image_info:
community.docker.docker_image_info:
name: "{{ iname_prefix }}-tagged-1:latest"
register: info_1
- assert:
- ansible.builtin.assert:
that:
- remove_1_check is not changed
- remove_1_check.diff == remove_1.diff
@ -70,7 +70,7 @@
- info_1.images | length == 0
- name: Tag image 1
docker_image_tag:
community.docker.docker_image_tag:
name: "{{ image }}"
repository:
- "{{ iname_prefix }}-tagged-1:latest"
@ -78,24 +78,24 @@
- "{{ iname_prefix }}-tagged-1:bar"
- name: Remove tagged image (check mode)
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ iname_prefix }}-tagged-1:latest"
register: remove_2_check
check_mode: true
diff: true
- name: Remove tagged image
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ iname_prefix }}-tagged-1:latest"
register: remove_2
diff: true
- name: Inspect image
docker_image_info:
community.docker.docker_image_info:
name: "{{ iname_prefix }}-tagged-1:latest"
register: info_2
- assert:
- ansible.builtin.assert:
that:
- remove_2_check is changed
- remove_2_check.diff == remove_2.diff
@ -114,19 +114,19 @@
- info_2.images | length == 0
- name: Remove tagged image (idempotent, check mode)
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ iname_prefix }}-tagged-1:latest"
register: remove_3_check
check_mode: true
diff: true
- name: Remove tagged image (idempotent)
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ iname_prefix }}-tagged-1:latest"
register: remove_3
diff: true
- assert:
- ansible.builtin.assert:
that:
- remove_3_check is not changed
- remove_3_check.diff == remove_3.diff
@ -139,14 +139,14 @@
- remove_3_check.untagged == remove_3.untagged
- name: Inspect image with tag foo and bar
docker_image_info:
community.docker.docker_image_info:
name:
- "{{ iname_prefix }}-tagged-1:foo"
- "{{ iname_prefix }}-tagged-1:bar"
register: info_3
- name: Remove tagged image (force, check mode)
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ iname_prefix }}-tagged-1:foo"
force: true
register: remove_4_check
@ -154,20 +154,20 @@
diff: true
- name: Remove tagged image (force)
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ iname_prefix }}-tagged-1:foo"
force: true
register: remove_4
diff: true
- name: Inspect image with tag foo and bar
docker_image_info:
community.docker.docker_image_info:
name:
- "{{ iname_prefix }}-tagged-1:foo"
- "{{ iname_prefix }}-tagged-1:bar"
register: info_4
- assert:
- ansible.builtin.assert:
that:
- remove_4_check is changed
- remove_4_check.diff == remove_4.diff
@ -190,7 +190,7 @@
- info_4.images[0].Id == pulled_image.image.Id
- name: Remove image ID (force, idempotent, check mode)
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ iname_prefix }}-tagged-1:foo"
force: true
register: remove_5_check
@ -198,13 +198,13 @@
diff: true
- name: Remove image ID (force, idempotent)
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ iname_prefix }}-tagged-1:foo"
force: true
register: remove_5
diff: true
- assert:
- ansible.builtin.assert:
that:
- remove_5_check is not changed
- remove_5_check.diff == remove_5.diff
@ -217,7 +217,7 @@
- remove_5_check.untagged == remove_5.untagged
- name: Remove image ID (force, check mode)
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ pulled_image.image.Id }}"
force: true
register: remove_6_check
@ -225,20 +225,20 @@
diff: true
- name: Remove image ID (force)
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ pulled_image.image.Id }}"
force: true
register: remove_6
diff: true
- name: Inspect image with tag foo and bar
docker_image_info:
community.docker.docker_image_info:
name:
- "{{ iname_prefix }}-tagged-1:foo"
- "{{ iname_prefix }}-tagged-1:bar"
register: info_5
- assert:
- ansible.builtin.assert:
that:
- remove_6_check is changed
- remove_6_check.diff == remove_6.diff
@ -258,7 +258,7 @@
- info_5.images | length == 0
- name: Remove image ID (force, idempotent, check mode)
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ pulled_image.image.Id }}"
force: true
register: remove_7_check
@ -266,13 +266,13 @@
diff: true
- name: Remove image ID (force, idempotent)
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ pulled_image.image.Id }}"
force: true
register: remove_7
diff: true
- assert:
- ansible.builtin.assert:
that:
- remove_7_check is not changed
- remove_7_check.diff == remove_7.diff
@ -286,11 +286,11 @@
always:
- name: Remove tagged images
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ item }}"
loop: "{{ image_names }}"
when: docker_api_version is version('1.25', '>=')
- fail: msg="Too old docker / docker-py version to run docker_image_info tests!"
- ansible.builtin.fail: msg="Too old docker / docker-py version to run docker_image_info tests!"
when: not(docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

View File

@ -10,11 +10,11 @@
- block:
- name: Pick image prefix
set_fact:
ansible.builtin.set_fact:
iname_prefix: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
- name: Define image names
set_fact:
ansible.builtin.set_fact:
image_1: "{{ docker_test_image_hello_world }}"
image_2: "{{ docker_test_image_alpine }}"
image_3: "{{ docker_test_image_digest_base }}@sha256:{{ docker_test_image_digest_v1 }}"
@ -25,7 +25,7 @@
- "{{ iname_prefix }}-tagged-2:baz"
- name: Make sure images we work with are there
docker_image_pull:
community.docker.docker_image_pull:
name: "{{ item }}"
loop:
- "{{ image_1 }}"
@ -35,12 +35,12 @@
diff: true
- name: Remove tagged images
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ item }}"
loop: "{{ image_names }}"
- name: Tag image 1 (check mode)
docker_image_tag:
community.docker.docker_image_tag:
name: "{{ image_1 }}"
repository:
- "{{ iname_prefix }}-tagged-1:latest"
@ -50,7 +50,7 @@
check_mode: true
- name: Tag image 1
docker_image_tag:
community.docker.docker_image_tag:
name: "{{ image_1 }}"
repository:
- "{{ iname_prefix }}-tagged-1:latest"
@ -59,11 +59,11 @@
diff: true
- name: Fetch image infos
docker_image_info:
community.docker.docker_image_info:
name: "{{ image_names }}"
register: info_1
- assert:
- ansible.builtin.assert:
that:
- tag_1 is changed
- tag_1.diff.before.images | length == 2
@ -79,7 +79,7 @@
- tag_1_check == tag_1
- name: Tag image 1 (idempotent, check mode)
docker_image_tag:
community.docker.docker_image_tag:
name: "{{ image_1 }}"
repository:
- "{{ iname_prefix }}-tagged-1:latest"
@ -89,7 +89,7 @@
check_mode: true
- name: Tag image 1 (idempotent)
docker_image_tag:
community.docker.docker_image_tag:
name: "{{ image_1 }}"
repository:
- "{{ iname_prefix }}-tagged-1:latest"
@ -97,7 +97,7 @@
register: tag_2
diff: true
- assert:
- ansible.builtin.assert:
that:
- tag_2 is not changed
- tag_2.diff.before == tag_2.diff.after
@ -105,7 +105,7 @@
- tag_2_check == tag_2
- name: Tag image 1 (idempotent, different input format, check mode)
docker_image_tag:
community.docker.docker_image_tag:
name: "{{ image_1 }}"
tag: foo
repository:
@ -116,7 +116,7 @@
check_mode: true
- name: Tag image 1 (idempotent, different input format)
docker_image_tag:
community.docker.docker_image_tag:
name: "{{ image_1 }}"
tag: foo
repository:
@ -125,7 +125,7 @@
register: tag_3
diff: true
- assert:
- ansible.builtin.assert:
that:
- tag_3 is not changed
- tag_3.diff.before == tag_3.diff.after
@ -133,7 +133,7 @@
- tag_3_check == tag_3
- name: Tag image 1 (one more, check mode)
docker_image_tag:
community.docker.docker_image_tag:
name: "{{ image_1 }}"
repository:
- "{{ iname_prefix }}-tagged-1:latest"
@ -144,7 +144,7 @@
check_mode: true
- name: Tag image 1 (one more)
docker_image_tag:
community.docker.docker_image_tag:
name: "{{ image_1 }}"
repository:
- "{{ iname_prefix }}-tagged-1:latest"
@ -154,11 +154,11 @@
diff: true
- name: Fetch image infos
docker_image_info:
community.docker.docker_image_info:
name: "{{ image_names }}"
register: info_4
- assert:
- ansible.builtin.assert:
that:
- tag_4 is changed
- tag_4.diff.before.images | length == 3
@ -176,7 +176,7 @@
- tag_4_check == tag_4
- name: Tag image 2 (only change missing one, check mode)
docker_image_tag:
community.docker.docker_image_tag:
name: "{{ image_2 }}"
existing_images: keep
repository:
@ -188,7 +188,7 @@
check_mode: true
- name: Tag image 2 (only change missing one)
docker_image_tag:
community.docker.docker_image_tag:
name: "{{ image_2 }}"
existing_images: keep
repository:
@ -199,11 +199,11 @@
diff: true
- name: Fetch image infos
docker_image_info:
community.docker.docker_image_info:
name: "{{ image_names }}"
register: info_5
- assert:
- ansible.builtin.assert:
that:
- tag_5 is changed
- tag_5.diff.before.images | length == 3
@ -222,7 +222,7 @@
- tag_5_check == tag_5
- name: Tag image 2 (idempotent, check mode)
docker_image_tag:
community.docker.docker_image_tag:
name: "{{ image_2 }}"
existing_images: keep
repository:
@ -234,7 +234,7 @@
check_mode: true
- name: Tag image 2 (idempotent)
docker_image_tag:
community.docker.docker_image_tag:
name: "{{ image_2 }}"
existing_images: keep
repository:
@ -244,7 +244,7 @@
register: tag_6
diff: true
- assert:
- ansible.builtin.assert:
that:
- tag_6 is not changed
- tag_6.diff.before == tag_6.diff.after
@ -252,7 +252,7 @@
- tag_6_check == tag_6
- name: Tag image 2 (only change wrong ones, check mode)
docker_image_tag:
community.docker.docker_image_tag:
name: "{{ image_2 }}"
existing_images: overwrite
repository:
@ -264,7 +264,7 @@
check_mode: true
- name: Tag image 2 (only change wrong ones)
docker_image_tag:
community.docker.docker_image_tag:
name: "{{ image_2 }}"
existing_images: overwrite
repository:
@ -275,11 +275,11 @@
diff: true
- name: Fetch image infos
docker_image_info:
community.docker.docker_image_info:
name: "{{ image_names }}"
register: info_7
- assert:
- ansible.builtin.assert:
that:
- tag_7 is changed
- tag_7.diff.before.images | length == 3
@ -299,7 +299,7 @@
- tag_7_check == tag_7
- name: Tag image 2 (idempotent, check mode)
docker_image_tag:
community.docker.docker_image_tag:
name: "{{ image_2 }}"
existing_images: overwrite
repository:
@ -311,7 +311,7 @@
check_mode: true
- name: Tag image 2 (idempotent)
docker_image_tag:
community.docker.docker_image_tag:
name: "{{ image_2 }}"
existing_images: overwrite
repository:
@ -321,7 +321,7 @@
register: tag_8
diff: true
- assert:
- ansible.builtin.assert:
that:
- tag_8 is not changed
- tag_8.diff.before == tag_8.diff.after
@ -329,7 +329,7 @@
- tag_8_check == tag_8
- name: Tag image 3 (source image has digest)
docker_image_tag:
community.docker.docker_image_tag:
name: "{{ image_3 }}"
existing_images: overwrite
repository:
@ -337,7 +337,7 @@
register: tag_9
diff: true
- assert:
- ansible.builtin.assert:
that:
- tag_9 is changed
- tag_9.diff.before.images | length == 1
@ -345,7 +345,7 @@
- tag_9.diff.after.images[0].id == pulled_images.results[2].image.Id
- name: Tag image 3 (source image is ID)
docker_image_tag:
community.docker.docker_image_tag:
name: "{{ pulled_images.results[2].image.Id }}"
existing_images: overwrite
repository:
@ -353,7 +353,7 @@
register: tag_10
diff: true
- assert:
- ansible.builtin.assert:
that:
- tag_10 is changed
- tag_10.diff.before.images | length == 1
@ -361,7 +361,7 @@
- tag_10.diff.after.images[0].id == pulled_images.results[2].image.Id
- name: Tag image 3 (fail because of digest)
docker_image_tag:
community.docker.docker_image_tag:
name: "{{ image_3 }}"
existing_images: overwrite
repository:
@ -369,14 +369,14 @@
register: tag_11
ignore_errors: true
- assert:
- ansible.builtin.assert:
that:
- tag_11 is failed
- >-
tag_11.msg == ('repository[1] must not have a digest; got: ' ~ iname_prefix ~ '-tagged-2@sha256:' ~ docker_test_image_digest_v1)
- name: Tag image 3 (fail because of image ID)
docker_image_tag:
community.docker.docker_image_tag:
name: "{{ image_3 }}"
existing_images: overwrite
repository:
@ -384,7 +384,7 @@
register: tag_12
ignore_errors: true
- assert:
- ansible.builtin.assert:
that:
- tag_12 is failed
- >-
@ -392,11 +392,11 @@
always:
- name: Remove tagged images
docker_image_remove:
community.docker.docker_image_remove:
name: "{{ item }}"
loop: "{{ image_names }}"
when: docker_api_version is version('1.25', '>=')
- fail: msg="Too old docker / docker-py version to run docker_image_info tests!"
- ansible.builtin.fail: msg="Too old docker / docker-py version to run docker_image_info tests!"
when: not(docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

View File

@ -9,5 +9,5 @@
####################################################################
- when: ansible_facts.distribution ~ ansible_facts.distribution_major_version not in ['CentOS6', 'RedHat6']
include_tasks:
ansible.builtin.include_tasks:
file: test.yml

View File

@ -4,4 +4,4 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: "Loading tasks from {{ test_name }}"
include_tasks: "{{ test_name }}"
ansible.builtin.include_tasks: "{{ test_name }}"

View File

@ -4,12 +4,12 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- block:
- include_tasks: run-test.yml
- ansible.builtin.include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"
loop_control:
loop_var: test_name
when: docker_api_version is version('1.25', '>=')
- fail: msg="Too old docker / docker-py version to run docker_image tests!"
- ansible.builtin.fail: msg="Too old docker / docker-py version to run docker_image tests!"
when: not(docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

View File

@ -5,14 +5,14 @@
- block:
- name: Log out server
docker_login:
community.docker.docker_login:
registry_url: "{{ registry_frontend_address }}"
username: testuser
password: hunter2
state: absent
- name: Log in with wrong password (check mode)
docker_login:
community.docker.docker_login:
registry_url: "{{ registry_frontend_address }}"
username: testuser
password: "1234"
@ -22,7 +22,7 @@
check_mode: true
- name: Log in with wrong password
docker_login:
community.docker.docker_login:
registry_url: "{{ registry_frontend_address }}"
username: testuser
password: "1234"
@ -31,7 +31,7 @@
ignore_errors: true
- name: Make sure that login failed
assert:
ansible.builtin.assert:
that:
- login_failed_check is failed
- "('login attempt to http://' ~ registry_frontend_address ~ '/v2/ failed') in login_failed_check.msg"
@ -39,7 +39,7 @@
- "('login attempt to http://' ~ registry_frontend_address ~ '/v2/ failed') in login_failed.msg"
- name: Log in (check mode)
docker_login:
community.docker.docker_login:
registry_url: "{{ registry_frontend_address }}"
username: testuser
password: hunter2
@ -48,7 +48,7 @@
check_mode: true
- name: Log in
docker_login:
community.docker.docker_login:
registry_url: "{{ registry_frontend_address }}"
username: testuser
password: hunter2
@ -56,12 +56,12 @@
register: login_2
- name: Get permissions of ~/.docker/config.json
stat:
ansible.builtin.stat:
path: ~/.docker/config.json
register: login_2_stat
- name: Log in (idempotent)
docker_login:
community.docker.docker_login:
registry_url: "{{ registry_frontend_address }}"
username: testuser
password: hunter2
@ -69,7 +69,7 @@
register: login_3
- name: Log in (idempotent, check mode)
docker_login:
community.docker.docker_login:
registry_url: "{{ registry_frontend_address }}"
username: testuser
password: hunter2
@ -78,7 +78,7 @@
check_mode: true
- name: Make sure that login worked
assert:
ansible.builtin.assert:
that:
- login_1 is changed
- login_2 is changed
@ -87,7 +87,7 @@
- login_2_stat.stat.mode == '0600'
- name: Log in again with wrong password (check mode)
docker_login:
community.docker.docker_login:
registry_url: "{{ registry_frontend_address }}"
username: testuser
password: "1234"
@ -97,7 +97,7 @@
check_mode: true
- name: Log in again with wrong password
docker_login:
community.docker.docker_login:
registry_url: "{{ registry_frontend_address }}"
username: testuser
password: "1234"
@ -106,7 +106,7 @@
ignore_errors: true
- name: Make sure that login failed again
assert:
ansible.builtin.assert:
that:
- login_failed_check is failed
- "('login attempt to http://' ~ registry_frontend_address ~ '/v2/ failed') in login_failed_check.msg"
@ -114,33 +114,33 @@
- "('login attempt to http://' ~ registry_frontend_address ~ '/v2/ failed') in login_failed.msg"
- name: Log out (check mode)
docker_login:
community.docker.docker_login:
registry_url: "{{ registry_frontend_address }}"
state: absent
register: logout_1
check_mode: true
- name: Log out
docker_login:
community.docker.docker_login:
registry_url: "{{ registry_frontend_address }}"
state: absent
register: logout_2
- name: Log out (idempotent)
docker_login:
community.docker.docker_login:
registry_url: "{{ registry_frontend_address }}"
state: absent
register: logout_3
- name: Log out (idempotent, check mode)
docker_login:
community.docker.docker_login:
registry_url: "{{ registry_frontend_address }}"
state: absent
register: logout_4
check_mode: true
- name: Make sure that login worked
assert:
ansible.builtin.assert:
that:
- logout_1 is changed
- logout_2 is changed

View File

@ -5,21 +5,21 @@
- block:
- name: Log out server 1
docker_login:
community.docker.docker_login:
registry_url: "{{ registry_frontend_address }}"
username: testuser
password: hunter2
state: absent
- name: Log out server 2
docker_login:
community.docker.docker_login:
registry_url: "{{ registry_frontend2_address }}"
username: testuser
password: hunter2
state: absent
- name: Log in server 1
docker_login:
community.docker.docker_login:
registry_url: "{{ registry_frontend_address }}"
username: testuser
password: hunter2
@ -27,7 +27,7 @@
register: login_1
- name: Log in server 2
docker_login:
community.docker.docker_login:
registry_url: "{{ registry_frontend2_address }}"
username: testuser
password: hunter2
@ -35,7 +35,7 @@
register: login_2
- name: Log in server 1 (idempotent)
docker_login:
community.docker.docker_login:
registry_url: "{{ registry_frontend_address }}"
username: testuser
password: hunter2
@ -43,7 +43,7 @@
register: login_1_2
- name: Log in server 2 (idempotent)
docker_login:
community.docker.docker_login:
registry_url: "{{ registry_frontend2_address }}"
username: testuser
password: hunter2
@ -51,7 +51,7 @@
register: login_2_2
- name: Make sure that login worked
assert:
ansible.builtin.assert:
that:
- login_1 is changed
- login_2 is changed

View File

@ -9,26 +9,26 @@
####################################################################
- name: List inspection results for all docker networks
docker_host_info:
community.docker.docker_host_info:
networks: true
verbose_output: true
register: all_networks
- name: Show inspection results for all docker networks
debug:
ansible.builtin.debug:
var: all_networks.networks
- name: Create random name prefix
set_fact:
ansible.builtin.set_fact:
name_prefix: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
cnames: []
dnetworks: []
- debug:
- ansible.builtin.debug:
msg: "Using name prefix {{ name_prefix }}"
- block:
- include_tasks: run-test.yml
- ansible.builtin.include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"
loop_control:
@ -36,13 +36,13 @@
always:
- name: "Make sure all containers are removed"
docker_container:
community.docker.docker_container:
name: "{{ item }}"
state: absent
force_kill: true
loop: "{{ cnames }}"
- name: "Make sure all networks are removed"
docker_network:
community.docker.docker_network:
name: "{{ item }}"
state: absent
force: true
@ -50,5 +50,5 @@
when: docker_api_version is version('1.25', '>=') # FIXME: find out API version!
- fail: msg="Too old docker / docker-py version to run docker_network tests!"
- ansible.builtin.fail: msg="Too old docker / docker-py version to run docker_network tests!"
when: not(docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

View File

@ -4,4 +4,4 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: "Loading tasks from {{ test_name }}"
include_tasks: "{{ test_name }}"
ansible.builtin.include_tasks: "{{ test_name }}"

View File

@ -4,19 +4,19 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Registering container and network names
set_fact:
ansible.builtin.set_fact:
cname_1: "{{ name_prefix ~ '-container-1' }}"
cname_2: "{{ name_prefix ~ '-container-2' }}"
cname_3: "{{ name_prefix ~ '-container-3' }}"
nname_1: "{{ name_prefix ~ '-network-1' }}"
nname_2: "{{ name_prefix ~ '-network-2' }}"
- name: Registering container and network names
set_fact:
ansible.builtin.set_fact:
cnames: "{{ cnames + [cname_1, cname_2, cname_3] }}"
dnetworks: "{{ dnetworks + [nname_1, nname_2] }}"
- name: Create containers
docker_container:
community.docker.docker_container:
name: "{{ container_name }}"
image: "{{ docker_test_image_alpine }}"
command: /bin/sleep 10m
@ -31,13 +31,13 @@
####################################################################
- name: Create network
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
state: present
register: networks_1
- name: Connect network to containers 1
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
state: present
connected:
@ -45,7 +45,7 @@
register: networks_2
- name: Connect network to containers 1 (idempotency)
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
state: present
connected:
@ -53,7 +53,7 @@
register: networks_2_idem
- name: Connect network to containers 1 and 2
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
state: present
connected:
@ -62,7 +62,7 @@
register: networks_3
- name: Connect network to containers 1 and 2 (idempotency)
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
state: present
connected:
@ -71,7 +71,7 @@
register: networks_3_idem
- name: Connect network to container 3
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
state: present
connected:
@ -80,7 +80,7 @@
register: networks_4
- name: Connect network to container 3 (idempotency)
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
state: present
connected:
@ -89,7 +89,7 @@
register: networks_4_idem
- name: Disconnect network from container 1
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
state: present
connected:
@ -98,7 +98,7 @@
register: networks_5
- name: Disconnect network from container 1 (idempotency)
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
state: present
connected:
@ -107,11 +107,11 @@
register: networks_5_idem
- name: Cleanup
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
state: absent
- assert:
- ansible.builtin.assert:
that:
- networks_1 is changed
- networks_2 is changed
@ -126,7 +126,7 @@
####################################################################
- name: Delete containers
docker_container:
community.docker.docker_container:
name: "{{ container_name }}"
state: absent
force_kill: true

View File

@ -4,21 +4,21 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Registering network names
set_fact:
ansible.builtin.set_fact:
nname_ipam_0: "{{ name_prefix ~ '-network-ipam-0' }}"
nname_ipam_1: "{{ name_prefix ~ '-network-ipam-1' }}"
nname_ipam_2: "{{ name_prefix ~ '-network-ipam-2' }}"
nname_ipam_3: "{{ name_prefix ~ '-network-ipam-3' }}"
- name: Registering network names
set_fact:
ansible.builtin.set_fact:
dnetworks: "{{ dnetworks + [nname_ipam_0, nname_ipam_1, nname_ipam_2, nname_ipam_3] }}"
#################### IPv4 IPAM config ####################
- name: Create network with custom IPAM config
docker_network:
community.docker.docker_network:
name: "{{ nname_ipam_1 }}"
ipam_config:
- subnet: 10.25.120.0/24
@ -29,12 +29,12 @@
host2: 10.25.120.4
register: network
- assert:
- ansible.builtin.assert:
that:
- network is changed
- name: Create network with custom IPAM config (idempotence)
docker_network:
community.docker.docker_network:
name: "{{ nname_ipam_1 }}"
ipam_config:
- subnet: 10.25.120.0/24
@ -45,12 +45,12 @@
host2: 10.25.120.4
register: network
- assert:
- ansible.builtin.assert:
that:
- network is not changed
- name: Change of network created with custom IPAM config
docker_network:
community.docker.docker_network:
name: "{{ nname_ipam_1 }}"
ipam_config:
- subnet: 10.25.121.0/24
@ -61,7 +61,7 @@
register: network
diff: true
- assert:
- ansible.builtin.assert:
that:
- network is changed
- network.diff.differences | length == 4
@ -71,18 +71,18 @@
- '"ipam_config[0].aux_addresses" in network.diff.differences'
- name: Remove gateway and iprange of network with custom IPAM config
docker_network:
community.docker.docker_network:
name: "{{ nname_ipam_1 }}"
ipam_config:
- subnet: 10.25.121.0/24
register: network
- assert:
- ansible.builtin.assert:
that:
- network is not changed
- name: Cleanup network with custom IPAM config
docker_network:
community.docker.docker_network:
name: "{{ nname_ipam_1 }}"
state: absent
@ -90,31 +90,31 @@
#################### IPv6 IPAM config ####################
- name: Create network with IPv6 IPAM config
docker_network:
community.docker.docker_network:
name: "{{ nname_ipam_2 }}"
enable_ipv6: true
ipam_config:
- subnet: fdd1:ac8c:0557:7ce0::/64
register: network
- assert:
- ansible.builtin.assert:
that:
- network is changed
- name: Create network with IPv6 IPAM config (idempotence)
docker_network:
community.docker.docker_network:
name: "{{ nname_ipam_2 }}"
enable_ipv6: true
ipam_config:
- subnet: fdd1:ac8c:0557:7ce0::/64
register: network
- assert:
- ansible.builtin.assert:
that:
- network is not changed
- name: Change subnet of network with IPv6 IPAM config
docker_network:
community.docker.docker_network:
name: "{{ nname_ipam_2 }}"
enable_ipv6: true
ipam_config:
@ -122,14 +122,14 @@
register: network
diff: true
- assert:
- ansible.builtin.assert:
that:
- network is changed
- network.diff.differences | length == 1
- network.diff.differences[0] == "ipam_config[0].subnet"
- name: Change subnet of network with IPv6 IPAM config
docker_network:
community.docker.docker_network:
name: "{{ nname_ipam_2 }}"
enable_ipv6: true
ipam_config:
@ -137,13 +137,13 @@
register: network
ignore_errors: true
- assert:
- ansible.builtin.assert:
that:
- network is failed
- "network.msg == '\"fdd1:ac8c:0557:7ce1::\" is not a valid CIDR'"
- name: Cleanup network with IPv6 IPAM config
docker_network:
community.docker.docker_network:
name: "{{ nname_ipam_2 }}"
state: absent
@ -151,7 +151,7 @@
#################### IPv4 and IPv6 network ####################
- name: Create network with IPv6 and custom IPv4 IPAM config
docker_network:
community.docker.docker_network:
name: "{{ nname_ipam_3 }}"
enable_ipv6: true
ipam_config:
@ -159,12 +159,12 @@
- subnet: fdd1:ac8c:0557:7ce2::/64
register: network
- assert:
- ansible.builtin.assert:
that:
- network is changed
- name: Change subnet order of network with IPv6 and custom IPv4 IPAM config (idempotence)
docker_network:
community.docker.docker_network:
name: "{{ nname_ipam_3 }}"
enable_ipv6: true
ipam_config:
@ -172,12 +172,12 @@
- subnet: 10.26.120.0/24
register: network
- assert:
- ansible.builtin.assert:
that:
- network is not changed
- name: Remove IPv6 from network with custom IPv4 and IPv6 IPAM config (change)
docker_network:
community.docker.docker_network:
name: "{{ nname_ipam_3 }}"
enable_ipv6: false
ipam_config:
@ -185,14 +185,14 @@
register: network
diff: true
- assert:
- ansible.builtin.assert:
that:
- network is changed
- network.diff.differences | length == 1
- network.diff.differences[0] == "enable_ipv6"
- name: Cleanup network with IPv6 and custom IPv4 IPAM config
docker_network:
community.docker.docker_network:
name: "{{ nname_ipam_3 }}"
state: absent
@ -201,7 +201,7 @@
- block:
- name: Create network with two IPv4 IPAM configs
docker_network:
community.docker.docker_network:
name: "{{ nname_ipam_3 }}"
driver: "macvlan"
driver_options:
@ -211,12 +211,12 @@
- subnet: 10.26.121.0/24
register: network
- assert:
- ansible.builtin.assert:
that:
- network is changed
- name: Create network with two IPv4 IPAM configs (idempotence)
docker_network:
community.docker.docker_network:
name: "{{ nname_ipam_3 }}"
driver: "macvlan"
driver_options:
@ -226,12 +226,12 @@
- subnet: 10.26.120.0/24
register: network
- assert:
- ansible.builtin.assert:
that:
- network is not changed
- name: Create network with two IPv4 IPAM configs (change)
docker_network:
community.docker.docker_network:
name: "{{ nname_ipam_3 }}"
driver: "macvlan"
driver_options:
@ -242,13 +242,13 @@
register: network
diff: true
- assert:
- ansible.builtin.assert:
that:
- network is changed
- network.diff.differences | length == 1
- name: Create network with one IPv4 IPAM config (no change)
docker_network:
community.docker.docker_network:
name: "{{ nname_ipam_3 }}"
driver: "macvlan"
driver_options:
@ -257,12 +257,12 @@
- subnet: 10.26.122.0/24
register: network
- assert:
- ansible.builtin.assert:
that:
- network is not changed
- name: Cleanup network
docker_network:
community.docker.docker_network:
name: "{{ nname_ipam_3 }}"
state: absent
@ -272,7 +272,7 @@
#################### IPAM driver options ####################
- name: Create network with IPAM driver options
docker_network:
community.docker.docker_network:
name: "{{ nname_ipam_3 }}"
ipam_driver: default
ipam_driver_options:
@ -280,7 +280,7 @@
register: network_1
ignore_errors: true
- name: Create network with IPAM driver options (idempotence)
docker_network:
community.docker.docker_network:
name: "{{ nname_ipam_3 }}"
ipam_driver: default
ipam_driver_options:
@ -289,7 +289,7 @@
register: network_2
ignore_errors: true
- name: Create network with IPAM driver options (change)
docker_network:
community.docker.docker_network:
name: "{{ nname_ipam_3 }}"
ipam_driver: default
ipam_driver_options:
@ -298,11 +298,11 @@
register: network_3
ignore_errors: true
- name: Cleanup network
docker_network:
community.docker.docker_network:
name: "{{ nname_ipam_3 }}"
state: absent
- assert:
- ansible.builtin.assert:
that:
- network_1 is changed
- network_2 is not changed

View File

@ -4,10 +4,10 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Registering network name
set_fact:
ansible.builtin.set_fact:
nname_1: "{{ name_prefix ~ '-network-1' }}"
- name: Registering network name
set_fact:
ansible.builtin.set_fact:
dnetworks: "{{ dnetworks + [nname_1] }}"
####################################################################
@ -15,30 +15,30 @@
####################################################################
- name: internal
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
internal: true
register: internal_1
- name: internal (idempotency)
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
internal: true
register: internal_2
- name: internal (change)
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
internal: false
register: internal_3
- name: cleanup
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
state: absent
force: true
- assert:
- ansible.builtin.assert:
that:
- internal_1 is changed
- internal_2 is not changed
@ -49,47 +49,47 @@
####################################################################
- name: driver_options
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
driver_options:
com.docker.network.bridge.enable_icc: 'false'
register: driver_options_1
- name: driver_options (idempotency)
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
driver_options:
com.docker.network.bridge.enable_icc: 'false'
register: driver_options_2
- name: driver_options (idempotency with string translation)
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
driver_options:
com.docker.network.bridge.enable_icc: false
register: driver_options_3
- name: driver_options (change)
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
driver_options:
com.docker.network.bridge.enable_icc: 'true'
register: driver_options_4
- name: driver_options (idempotency with string translation)
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
driver_options:
com.docker.network.bridge.enable_icc: true
register: driver_options_5
- name: cleanup
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
state: absent
force: true
- assert:
- ansible.builtin.assert:
that:
- driver_options_1 is changed
- driver_options_2 is not changed
@ -103,40 +103,40 @@
- block:
- name: scope
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
driver: bridge
scope: local
register: scope_1
- name: scope (idempotency)
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
driver: bridge
scope: local
register: scope_2
- name: swarm
docker_swarm:
community.docker.docker_swarm:
state: present
advertise_addr: "{{ ansible_default_ipv4.address | default('127.0.0.1') }}"
# Driver change alongside scope is intentional - bridge doesn't appear to support anything but local, and overlay can't downgrade to local. Additionally, overlay reports as swarm for swarm OR global, so no change is reported in that case.
# Test output indicates that the scope is altered, at least, so manual inspection will be required to verify this going forward, unless we come up with a test driver that supports multiple scopes.
- name: scope (change)
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
driver: overlay
scope: swarm
register: scope_3
- name: cleanup network
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
state: absent
force: true
- assert:
- ansible.builtin.assert:
that:
- scope_1 is changed
- scope_2 is not changed
@ -144,7 +144,7 @@
always:
- name: cleanup swarm
docker_swarm:
community.docker.docker_swarm:
state: absent
force: true
@ -153,33 +153,33 @@
####################################################################
- name: attachable
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
attachable: true
register: attachable_1
ignore_errors: true
- name: attachable (idempotency)
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
attachable: true
register: attachable_2
ignore_errors: true
- name: attachable (change)
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
attachable: false
register: attachable_3
ignore_errors: true
- name: cleanup
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
state: absent
force: true
- assert:
- ansible.builtin.assert:
that:
- attachable_1 is changed
- attachable_2 is not changed
@ -190,7 +190,7 @@
####################################################################
- name: labels
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
labels:
ansible.test.1: hello
@ -198,7 +198,7 @@
register: labels_1
- name: labels (idempotency)
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
labels:
ansible.test.2: world
@ -206,14 +206,14 @@
register: labels_2
- name: labels (less labels)
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
labels:
ansible.test.1: hello
register: labels_3
- name: labels (more labels)
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
labels:
ansible.test.1: hello
@ -221,12 +221,12 @@
register: labels_4
- name: cleanup
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
state: absent
force: true
- assert:
- ansible.builtin.assert:
that:
- labels_1 is changed
- labels_2 is not changed

View File

@ -4,16 +4,16 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Registering network name
set_fact:
ansible.builtin.set_fact:
nname_1: "{{ name_prefix ~ '-network-1' }}"
- name: Registering network name
set_fact:
ansible.builtin.set_fact:
dnetworks: "{{ dnetworks + [nname_1] }}"
- block:
# Overlay networks require swarm initialization before they'll work
- name: swarm
docker_swarm:
community.docker.docker_swarm:
state: present
advertise_addr: "{{ ansible_default_ipv4.address | default('127.0.0.1') }}"
@ -22,7 +22,7 @@
####################################################################
- name: overlay
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
driver: overlay
driver_options:
@ -30,7 +30,7 @@
register: overlay_1
- name: overlay (idempotency)
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
driver: overlay
driver_options:
@ -38,18 +38,18 @@
register: overlay_2
- name: overlay (change)
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
driver: bridge
register: overlay_3
- name: cleanup network
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
state: absent
force: true
- assert:
- ansible.builtin.assert:
that:
- overlay_1 is changed
- overlay_2 is not changed
@ -60,38 +60,38 @@
####################################################################
- name: cleanup default swarm ingress network
docker_network:
community.docker.docker_network:
name: ingress
state: absent
- name: ingress
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
driver: overlay
ingress: true
register: ingress_1
- name: ingress (idempotency)
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
driver: overlay
ingress: true
register: ingress_2
- name: ingress (change)
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
driver: overlay
ingress: false
register: ingress_3
- name: cleanup network
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
state: absent
force: true
- assert:
- ansible.builtin.assert:
that:
- ingress_1 is changed
- ingress_2 is not changed
@ -99,6 +99,6 @@
always:
- name: cleanup swarm
docker_swarm:
community.docker.docker_swarm:
state: absent
force: true

View File

@ -4,29 +4,29 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Registering container and network names
set_fact:
ansible.builtin.set_fact:
nname_1: "{{ name_prefix ~ '-network-foo' }}"
nname_2: "{{ name_prefix ~ '-network-foobar' }}"
- name: Registering container and network names
set_fact:
ansible.builtin.set_fact:
dnetworks: "{{ dnetworks + [nname_1, nname_2] }}"
####################################################################
- name: Create network (superstring)
docker_network:
community.docker.docker_network:
name: "{{ nname_2 }}"
state: present
register: networks_1
- name: Create network (substring)
docker_network:
community.docker.docker_network:
name: "{{ nname_1 }}"
state: present
register: networks_2
- name: Cleanup
docker_network:
community.docker.docker_network:
name: "{{ network_name }}"
state: absent
loop:
@ -35,7 +35,7 @@
loop_control:
loop_var: network_name
- assert:
- ansible.builtin.assert:
that:
- networks_1 is changed
- networks_2 is changed

View File

@ -10,71 +10,71 @@
- block:
- name: Create random network name
set_fact:
ansible.builtin.set_fact:
nname: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
- name: Make sure network is not there
docker_network:
community.docker.docker_network:
name: "{{ nname }}"
state: absent
force: true
- name: Inspect a non-present network
docker_network_info:
community.docker.docker_network_info:
name: "{{ nname }}"
register: result
- assert:
- ansible.builtin.assert:
that:
- "not result.exists"
- "'network' in result"
- "result.network is none"
- name: Make sure network exists
docker_network:
community.docker.docker_network:
name: "{{ nname }}"
state: present
- name: Inspect a present network
docker_network_info:
community.docker.docker_network_info:
name: "{{ nname }}"
register: result
- name: Dump docker_network_info result
debug: var=result
ansible.builtin.debug: var=result
- name: "Comparison: use 'docker network inspect'"
command: docker network inspect "{{ nname }}"
ansible.builtin.command: docker network inspect "{{ nname }}"
register: docker_inspect
ignore_errors: true
- block:
- set_fact:
- ansible.builtin.set_fact:
docker_inspect_result: "{{ docker_inspect.stdout | from_json }}"
- name: Dump docker inspect result
debug: var=docker_inspect_result
ansible.builtin.debug: var=docker_inspect_result
when: docker_inspect is not failed
- name: Cleanup
docker_network:
community.docker.docker_network:
name: "{{ nname }}"
state: absent
force: true
- assert:
- ansible.builtin.assert:
that:
- result.exists
- "'network' in result"
- "result.network is truthy"
- assert:
- ansible.builtin.assert:
that:
- "result.network == docker_inspect_result[0]"
when: docker_inspect is not failed
- assert:
- ansible.builtin.assert:
that:
- "'is too new. Maximum supported API version is' in docker_inspect.stderr"
when: docker_inspect is failed
when: docker_api_version is version('1.25', '>=')
- fail: msg="Too old docker / docker-py version to run docker_network_info tests!"
- ansible.builtin.fail: msg="Too old docker / docker-py version to run docker_network_info tests!"
when: not(docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

View File

@ -10,32 +10,32 @@
# Run the tests
- block:
- include_tasks: test_node.yml
- ansible.builtin.include_tasks: test_node.yml
always:
- name: Cleanup (trying)
docker_swarm:
community.docker.docker_swarm:
state: absent
force: true
diff: false
ignore_errors: true
- name: Restart docker daemon
service:
ansible.builtin.service:
name: docker
state: restarted
become: true
- name: Wait for docker daemon to be fully restarted
command: docker ps
ansible.builtin.command: docker ps
ignore_errors: true
- name: Cleanup
docker_swarm:
community.docker.docker_swarm:
state: absent
force: true
diff: false
when: docker_py_version is version('2.4.0', '>=') and docker_api_version is version('1.25', '>=')
- fail: msg="Too old docker / docker-py version to run docker_node tests!"
- ansible.builtin.fail: msg="Too old docker / docker-py version to run docker_node tests!"
when: not(docker_py_version is version('2.4.0', '>=') and docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

View File

@ -5,29 +5,29 @@
- block:
- name: Make sure we're not already using Docker swarm
docker_swarm:
community.docker.docker_swarm:
state: absent
force: true
- name: Try to get docker_node_info when docker is not running in swarm mode
docker_node_info:
community.docker.docker_node_info:
ignore_errors: true
register: output
- name: assert failure when called when swarm is not in use or not run on manager node
assert:
ansible.builtin.assert:
that:
- 'output is failed'
- 'output.msg == "Error running docker swarm module: must run on swarm manager node"'
- name: Create a Swarm cluster
docker_swarm:
community.docker.docker_swarm:
state: present
advertise_addr: "{{ansible_default_ipv4.address | default('127.0.0.1')}}"
register: output
- name: assert changed when create a new swarm cluster
assert:
ansible.builtin.assert:
that:
- 'output is changed'
- '(output.actions[0] | regex_search("New Swarm cluster created: ")) is truthy'
@ -35,17 +35,17 @@
- 'output.swarm_facts.JoinTokens.Worker is truthy'
- name: Try to get docker_node_info when docker is running in swarm mode and as manager
docker_node_info:
community.docker.docker_node_info:
register: output
- name: assert reading docker swarm node facts
assert:
ansible.builtin.assert:
that:
- 'output.nodes | length > 0'
- 'output.nodes[0].ID is string'
- name: Register node ID
set_fact:
ansible.builtin.set_fact:
nodeid: "{{ output.nodes[0].ID }}"
####################################################################
@ -53,33 +53,33 @@
####################################################################
- name: Try to set node as manager (check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
role: manager
check_mode: true
register: set_as_manager_1
- name: Try to set node as manager
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
role: manager
register: set_as_manager_2
- name: Try to set node as manager (idempotent)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
role: manager
register: set_as_manager_3
- name: Try to set node as manager (idempotent check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
role: manager
check_mode: true
register: set_as_manager_4
- name: assert that node role does has not changed
assert:
ansible.builtin.assert:
that:
- 'set_as_manager_1 is not changed'
- 'set_as_manager_2 is not changed'
@ -95,21 +95,21 @@
####################################################################
- name: Try to set node as worker (check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
role: worker
check_mode: true
register: set_as_worker_1
- name: Try to set node as worker
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
role: worker
ignore_errors: true
register: set_as_worker_2
- name: assert that node cannot change role to worker
assert:
ansible.builtin.assert:
that:
- 'set_as_worker_1 is changed'
- 'set_as_worker_2 is failed'
@ -120,33 +120,33 @@
####################################################################
- name: Try to set node availability as paused (check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
availability: pause
check_mode: true
register: set_as_paused_1
- name: Try to set node availability as paused
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
availability: pause
register: set_as_paused_2
- name: Try to set node availability as paused (idempotent)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
availability: pause
register: set_as_paused_3
- name: Try to set node availability as paused (idempotent check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
availability: pause
check_mode: true
register: set_as_paused_4
- name: assert node changed availability to paused
assert:
ansible.builtin.assert:
that:
- 'set_as_paused_1 is changed'
- 'set_as_paused_2 is changed'
@ -159,33 +159,33 @@
####################################################################
- name: Try to set node availability as drained (check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
availability: drain
check_mode: true
register: output_drain_1
- name: Try to set node availability as drained
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
availability: drain
register: output_drain_2
- name: Try to set node availability as drained (idempotent)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
availability: drain
register: output_drain_3
- name: Try to set node availability as drained (idempotent check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
availability: drain
check_mode: true
register: output_drain_4
- name: assert node changed availability to drained
assert:
ansible.builtin.assert:
that:
- 'output_drain_1 is changed'
- 'output_drain_2 is changed'
@ -199,33 +199,33 @@
####################################################################
- name: Try to set node availability as active (check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
availability: active
check_mode: true
register: output_active_1
- name: Try to set node availability as active
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
availability: active
register: output_active_2
- name: Try to set node availability as active (idempotent)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
availability: active
register: output_active_3
- name: Try to set node availability as active (idempotent check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
availability: active
check_mode: true
register: output_active_4
- name: assert node changed availability to active
assert:
ansible.builtin.assert:
that:
- 'output_active_1 is changed'
- 'output_active_2 is changed'
@ -238,7 +238,7 @@
####################################################################
- name: Try to add single label to swarm node (check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label1: value1
@ -246,21 +246,21 @@
register: output_add_single_label_1
- name: Try to add single label to swarm node
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label1: value1
register: output_add_single_label_2
- name: Try to add single label to swarm node (idempotent)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label1: value1
register: output_add_single_label_3
- name: Try to add single label to swarm node (idempotent check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label1: value1
@ -268,7 +268,7 @@
register: output_add_single_label_4
- name: assert adding single label to swarm node
assert:
ansible.builtin.assert:
that:
- 'output_add_single_label_1 is changed'
- 'output_add_single_label_2 is changed'
@ -282,7 +282,7 @@
####################################################################
- name: Try to add five labels to swarm node (check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label2: value2
@ -294,7 +294,7 @@
register: output_add_multiple_labels_1
- name: Try to add five labels to swarm node
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label2: value2
@ -305,7 +305,7 @@
register: output_add_multiple_labels_2
- name: Try to add five labels to swarm node (idempotent)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label2: value2
@ -316,7 +316,7 @@
register: output_add_multiple_labels_3
- name: Try to add five labels to swarm node (idempotent check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label2: value2
@ -328,7 +328,7 @@
register: output_add_multiple_labels_4
- name: assert adding multiple labels to swarm node
assert:
ansible.builtin.assert:
that:
- 'output_add_multiple_labels_1 is changed'
- 'output_add_multiple_labels_2 is changed'
@ -343,7 +343,7 @@
####################################################################
- name: Update value of existing label (check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label1: value1111
@ -351,21 +351,21 @@
register: output_update_label_1
- name: Update value of existing label
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label1: value1111
register: output_update_label_2
- name: Update value of existing label (idempotent)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label1: value1111
register: output_update_label_3
- name: Update value of existing label (idempotent check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label1: value1111
@ -373,7 +373,7 @@
register: output_update_label_4
- name: assert updating single label assigned to swarm node
assert:
ansible.builtin.assert:
that:
- 'output_update_label_1 is changed'
- 'output_update_label_2 is changed'
@ -388,7 +388,7 @@
####################################################################
- name: Update value of multiple existing label (check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label2: value2222
@ -397,7 +397,7 @@
register: output_update_labels_1
- name: Update value of multiple existing label
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label2: value2222
@ -405,7 +405,7 @@
register: output_update_labels_2
- name: Update value of multiple existing label (idempotent)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label2: value2222
@ -413,7 +413,7 @@
register: output_update_labels_3
- name: Update value of multiple existing label (idempotent check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label2: value2222
@ -422,7 +422,7 @@
register: output_update_labels_4
- name: assert updating multiple labels assigned to swarm node
assert:
ansible.builtin.assert:
that:
- 'output_update_labels_1 is changed'
- 'output_update_labels_2 is changed'
@ -438,7 +438,7 @@
####################################################################
- name: Try to remove single existing label from swarm node (check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels_to_remove:
- label1
@ -446,21 +446,21 @@
register: output_remove_label_1
- name: Try to remove single existing label from swarm node
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels_to_remove:
- label1
register: output_remove_label_2
- name: Try to remove single existing label from swarm node (idempotent)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels_to_remove:
- label1
register: output_remove_label_3
- name: Try to remove single existing label from swarm node (idempotent check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels_to_remove:
- label1
@ -468,7 +468,7 @@
register: output_remove_label_4
- name: assert removing single label from swarm node
assert:
ansible.builtin.assert:
that:
- 'output_remove_label_1 is changed'
- 'output_remove_label_2 is changed'
@ -485,7 +485,7 @@
####################################################################
- name: Try to remove single non-existing label from swarm node (check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels_to_remove:
- labelnotexist
@ -493,21 +493,21 @@
register: output_remove_nonexist_label_1
- name: Try to remove single non-existing label from swarm node
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels_to_remove:
- labelnotexist
register: output_remove_nonexist_label_2
- name: Try to remove single non-existing label from swarm node (idempotent)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels_to_remove:
- labelnotexist
register: output_remove_nonexist_label_3
- name: Try to remove single non-existing label from swarm node (idempotent check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels_to_remove:
- labelnotexist
@ -515,7 +515,7 @@
register: output_remove_nonexist_label_4
- name: assert removing single non-existing label from swarm node
assert:
ansible.builtin.assert:
that:
- 'output_remove_nonexist_label_1 is not changed'
- 'output_remove_nonexist_label_2 is not changed'
@ -531,7 +531,7 @@
####################################################################
- name: Try to remove two existing labels from swarm node (check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels_to_remove:
- label2
@ -540,7 +540,7 @@
register: output_remove_label_1
- name: Try to remove two existing labels from swarm node
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels_to_remove:
- label2
@ -548,7 +548,7 @@
register: output_remove_label_2
- name: Try to remove two existing labels from swarm node (idempotent)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels_to_remove:
- label2
@ -556,7 +556,7 @@
register: output_remove_label_3
- name: Try to remove two existing labels from swarm node (idempotent check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels_to_remove:
- label2
@ -565,7 +565,7 @@
register: output_remove_label_4
- name: assert removing multiple labels from swarm node
assert:
ansible.builtin.assert:
that:
- 'output_remove_label_1 is changed'
- 'output_remove_label_2 is changed'
@ -581,7 +581,7 @@
####################################################################
- name: Try to remove mix of existing amd non-existing labels from swarm node (check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels_to_remove:
- label4
@ -590,7 +590,7 @@
register: output_remove_mix_labels_1
- name: Try to remove mix of existing amd non-existing labels from swarm node
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels_to_remove:
- label4
@ -598,7 +598,7 @@
register: output_remove_mix_labels_2
- name: Try to remove mix of existing amd non-existing labels from swarm node (idempotent)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels_to_remove:
- label4
@ -606,7 +606,7 @@
register: output_remove_mix_labels_3
- name: Try to remove mix of existing amd non-existing labels from swarm node (idempotent check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels_to_remove:
- label4
@ -615,7 +615,7 @@
register: output_remove_mix_labels_4
- name: assert removing mix of existing and non-existing labels from swarm node
assert:
ansible.builtin.assert:
that:
- 'output_remove_mix_labels_1 is changed'
- 'output_remove_mix_labels_2 is changed'
@ -631,7 +631,7 @@
####################################################################
- name: Try to add and remove nonoverlapping labels at the same time (check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label7: value7
@ -642,7 +642,7 @@
register: output_add_del_labels_1
- name: Try to add and remove nonoverlapping labels at the same time
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label7: value7
@ -652,7 +652,7 @@
register: output_add_del_labels_2
- name: Try to add and remove nonoverlapping labels at the same time (idempotent)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label7: value7
@ -662,7 +662,7 @@
register: output_add_del_labels_3
- name: Try to add and remove nonoverlapping labels at the same time (idempotent check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label7: value7
@ -673,7 +673,7 @@
register: output_add_del_labels_4
- name: assert adding and removing nonoverlapping labels from swarm node
assert:
ansible.builtin.assert:
that:
- 'output_add_del_labels_1 is changed'
- 'output_add_del_labels_2 is changed'
@ -688,7 +688,7 @@
####################################################################
- name: Try to add or update and remove overlapping labels at the same time (check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label22: value22
@ -700,7 +700,7 @@
register: output_add_del_overlap_labels_1
- name: Try to add or update and remove overlapping labels at the same time
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label22: value22
@ -711,7 +711,7 @@
register: output_add_del_overlap_labels_2
- name: Try to add or update and remove overlapping labels at the same time (idempotent)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label22: value22
@ -722,7 +722,7 @@
register: output_add_del_overlap_labels_3
- name: Try to add or update and remove overlapping labels at the same time (idempotent check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label22: value22
@ -734,7 +734,7 @@
register: output_add_del_overlap_labels_4
- name: assert adding or updating and removing overlapping labels from swarm node
assert:
ansible.builtin.assert:
that:
- 'output_add_del_overlap_labels_1 is changed'
- 'output_add_del_overlap_labels_2 is changed'
@ -750,7 +750,7 @@
####################################################################
- name: Replace labels on swarm node (check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label11: value11
@ -760,7 +760,7 @@
register: output_replace_labels_1
- name: Replace labels on swarm node
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label11: value11
@ -769,7 +769,7 @@
register: output_replace_labels_2
- name: Replace labels on swarm node (idempotent)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label11: value11
@ -778,7 +778,7 @@
register: output_replace_labels_3
- name: Replace labels on swarm node (idempotent check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels:
label11: value11
@ -788,7 +788,7 @@
register: output_replace_labels_4
- name: assert replacing labels from swarm node
assert:
ansible.builtin.assert:
that:
- 'output_replace_labels_1 is changed'
- 'output_replace_labels_2 is changed'
@ -803,33 +803,33 @@
####################################################################
- name: Remove all labels from swarm node (check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels_state: replace
check_mode: true
register: output_remove_labels_1
- name: Remove all labels from swarm node
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels_state: replace
register: output_remove_labels_2
- name: Remove all labels from swarm node (idempotent)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels_state: replace
register: output_remove_labels_3
- name: Remove all labels from swarm node (idempotent check)
docker_node:
community.docker.docker_node:
hostname: "{{ nodeid }}"
labels_state: replace
check_mode: true
register: output_remove_labels_4
- name: assert removing all labels from swarm node
assert:
ansible.builtin.assert:
that:
- 'output_remove_labels_1 is changed'
- 'output_remove_labels_2 is changed'
@ -839,6 +839,6 @@
always:
- name: Cleanup
docker_swarm:
community.docker.docker_swarm:
state: absent
force: true

View File

@ -8,8 +8,8 @@
# and should not be used as examples of how to write Ansible roles #
####################################################################
- include_tasks: test_node_info.yml
- ansible.builtin.include_tasks: test_node_info.yml
when: docker_py_version is version('2.4.0', '>=') and docker_api_version is version('1.25', '>=')
- fail: msg="Too old docker / docker-py version to run docker_node_info tests!"
- ansible.builtin.fail: msg="Too old docker / docker-py version to run docker_node_info tests!"
when: not(docker_py_version is version('2.4.0', '>=') and docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

View File

@ -5,29 +5,29 @@
- block:
- name: Make sure we're not already using Docker swarm
docker_swarm:
community.docker.docker_swarm:
state: absent
force: true
- name: Try to get docker_node_info when docker is not running in swarm mode
docker_node_info:
community.docker.docker_node_info:
ignore_errors: true
register: output
- name: assert failure when called when swarm is not in use or not run on manager node
assert:
ansible.builtin.assert:
that:
- 'output is failed'
- 'output.msg == "Error running docker swarm module: must run on swarm manager node"'
- name: Create a Swarm cluster
docker_swarm:
community.docker.docker_swarm:
state: present
advertise_addr: "{{ansible_default_ipv4.address | default('127.0.0.1')}}"
register: output
- name: assert changed when create a new swarm cluster
assert:
ansible.builtin.assert:
that:
- 'output is changed'
- '(output.actions[0] | regex_search("New Swarm cluster created: ")) is truthy'
@ -35,58 +35,58 @@
- 'output.swarm_facts.JoinTokens.Worker is truthy'
- name: Try to get docker_node_info when docker is running in swarm mode and as manager
docker_node_info:
community.docker.docker_node_info:
register: output
- name: assert reading docker swarm node facts
assert:
ansible.builtin.assert:
that:
- 'output.nodes | length > 0'
- 'output.nodes[0].ID is string'
- name: Try to get docker_node_info using the self parameter
docker_node_info:
community.docker.docker_node_info:
self: true
register: output
- name: assert reading swarm facts with list of nodes option
assert:
ansible.builtin.assert:
that:
- 'output.nodes | length == 1'
- 'output.nodes[0].ID is string'
- name: Get local docker node name
set_fact:
ansible.builtin.set_fact:
localnodename: "{{ output.nodes[0].Description.Hostname }}"
- name: Try to get docker_node_info using the local node name as parameter
docker_node_info:
community.docker.docker_node_info:
name: "{{ localnodename }}"
register: output
- name: assert reading reading swarm facts and using node filter (random node name)
assert:
ansible.builtin.assert:
that:
- 'output.nodes | length == 1'
- 'output.nodes[0].ID is string'
- name: Create random name
set_fact:
ansible.builtin.set_fact:
randomnodename: "{{ 'node-%0x' % ((2**32) | random) }}"
- name: Try to get docker_node_info using random node name as parameter
docker_node_info:
community.docker.docker_node_info:
name: "{{ randomnodename }}"
register: output
- name: assert reading reading swarm facts and using node filter (random node name)
assert:
ansible.builtin.assert:
that:
- 'output.nodes | length == 0'
always:
- name: Cleanup
docker_swarm:
community.docker.docker_swarm:
state: absent
force: true

View File

@ -4,20 +4,20 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Create random name prefix
set_fact:
ansible.builtin.set_fact:
name_prefix: "vieux/sshfs"
plugin_names: []
- debug:
- ansible.builtin.debug:
msg: "Using name prefix {{ name_prefix }}"
- name: Check whether /dev/fuse exists
stat:
ansible.builtin.stat:
path: /dev/fuse
register: dev_fuse_stat
- block:
- include_tasks: run-test.yml
- ansible.builtin.include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"
loop_control:
@ -25,12 +25,12 @@
always:
- name: "Make sure plugin is removed"
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ item }}"
state: absent
with_items: "{{ plugin_names }}"
when: docker_api_version is version('1.25', '>=') and dev_fuse_stat.stat.exists
- fail: msg="Too old docker / docker-py version to run docker_plugin tests!"
- ansible.builtin.fail: msg="Too old docker / docker-py version to run docker_plugin tests!"
when: not(docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

View File

@ -4,4 +4,4 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: "Loading tasks from {{ test_name }}"
include_tasks: "{{ test_name }}"
ansible.builtin.include_tasks: "{{ test_name }}"

View File

@ -4,127 +4,127 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Registering plugin name
set_fact:
ansible.builtin.set_fact:
plugin_name: "{{ name_prefix }}"
- name: Registering container name
set_fact:
ansible.builtin.set_fact:
plugin_names: "{{ plugin_names + [plugin_name] }}"
############ basic test ############
####################################
- name: Create a plugin (check mode)
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
state: present
register: create_1_check
check_mode: true
- name: Create a plugin
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
state: present
register: create_1
- name: Create a plugin (Idempotent, check mode)
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
state: present
register: create_2_check
check_mode: true
- name: Create a plugin (Idempotent)
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
state: present
register: create_2
- name: Enable a plugin (check mode)
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
state: enable
register: create_3_check
check_mode: true
- name: Enable a plugin
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
state: enable
register: create_3
- name: Enable a plugin (Idempotent, check mode)
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
state: enable
register: create_4_check
check_mode: true
- name: Enable a plugin (Idempotent)
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
state: enable
register: create_4
- name: Disable a plugin (check mode)
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
state: disable
register: absent_1_check
check_mode: true
- name: Disable a plugin
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
state: disable
register: absent_1
- name: Disable a plugin (Idempotent, check mode)
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
state: disable
register: absent_2_check
check_mode: true
- name: Disable a plugin (Idempotent)
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
state: disable
register: absent_2
- name: Remove a plugin (check mode)
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
state: absent
register: absent_3_check
check_mode: true
- name: Remove a plugin
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
state: absent
register: absent_3
- name: Remove a plugin (Idempotent, check mode)
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
state: absent
register: absent_4_check
check_mode: true
- name: Remove a plugin (Idempotent)
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
state: absent
register: absent_4
- name: Cleanup
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
state: absent
force_remove: true
- assert:
- ansible.builtin.assert:
that:
- create_1_check is changed
- create_1 is changed
@ -147,7 +147,7 @@
########################################
- name: Install a plugin with options
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
plugin_options:
DEBUG: '1'
@ -155,7 +155,7 @@
register: create_1
- name: Install a plugin with options (idempotent)
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
plugin_options:
DEBUG: '1'
@ -163,7 +163,7 @@
register: create_2
- name: Install a plugin with different options
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
plugin_options:
DEBUG: '0'
@ -171,7 +171,7 @@
register: update_1
- name: Install a plugin with different options (idempotent)
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
plugin_options:
DEBUG: '0'
@ -179,12 +179,12 @@
register: update_2
- name: Cleanup
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
state: absent
force_remove: true
- assert:
- ansible.builtin.assert:
that:
- create_1 is changed
- create_2 is not changed

View File

@ -4,67 +4,67 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Register plugin name and alias
set_fact:
ansible.builtin.set_fact:
plugin_name: "{{ name_prefix }}"
alias: "test"
- name: Create a plugin with an alias
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
alias: "{{ alias }}"
state: present
register: create_1
- name: Create a plugin with an alias (Idempotent)
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
alias: "{{ alias }}"
state: present
register: create_2
- name: Enable a plugin with an alias
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
alias: "{{ alias }}"
state: enable
register: create_3
- name: Enable a plugin with an alias (Idempotent)
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
alias: "{{ alias }}"
state: enable
register: create_4
- name: Disable a plugin with an alias
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
alias: "{{ alias }}"
state: disable
register: absent_1
- name: Disable a plugin with an alias (Idempotent)
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
alias: "{{ alias }}"
state: disable
register: absent_2
- name: Remove a plugin with an alias
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
alias: "{{ alias }}"
state: absent
register: absent_3
- name: Remove a plugin with an alias (Idempotent)
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
alias: "{{ alias }}"
state: absent
register: absent_4
- assert:
- ansible.builtin.assert:
that:
- create_1 is changed
- create_2 is not changed
@ -76,7 +76,7 @@
- absent_4 is not changed
- name: Cleanup plugin with an alias
docker_plugin:
community.docker.docker_plugin:
plugin_name: "{{ plugin_name }}"
alias: "{{ alias }}"
state: absent

Some files were not shown because too many files have changed in this diff Show More