community.docker/tests/integration/targets/docker_container/tasks/main.yml
Felix Fontein 90c4b4c543
docker_image(_pull), docker_container: fix compatibility with Docker 29.0.0 (#1192)
* Add debug flag to failing task.

* Add more debug output.

* Fix pull idempotency.

* Revert "Add more debug output."

This reverts commit 64020149bf.

* Fix casing.

* Remove unreliable test.

* Add 'debug: true' to all tasks.

* Reformat.

* Fix idempotency problem for IPv6 addresses.

* Fix expose ranges handling.

* Update changelog fragment to also mention other affected modules.
2025-11-15 17:13:46 +01:00

74 lines
2.3 KiB
YAML

---
# Copyright (c) Ansible Project
# 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
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
- name: Gather facts on controller
ansible.builtin.setup:
gather_subset: '!all'
delegate_to: localhost
delegate_facts: true
run_once: true
- name: Make sure ipaddress is available on controller
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
ansible.builtin.set_fact:
cname_prefix: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
cnames: []
inames: []
dnetworks: []
- ansible.builtin.debug:
msg: "Using container name prefix {{ cname_prefix }}"
- name: Retrieve docker host info
community.docker.docker_host_info:
register: docker_host_info
# Run the tests
- module_defaults:
community.general.docker_container:
debug: true
block:
- ansible.builtin.include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"
loop_control:
loop_var: test_name
always:
- name: "Make sure all containers are removed"
community.docker.docker_container:
name: "{{ item }}"
state: absent
force_kill: true
with_items: "{{ cnames }}"
diff: false
- name: "Make sure all images are removed"
community.docker.docker_image_remove:
name: "{{ item }}"
with_items: "{{ inames }}"
- name: "Make sure all networks are removed"
community.docker.docker_network:
name: "{{ item }}"
state: absent
force: true
with_items: "{{ dnetworks }}"
diff: false
when: docker_api_version is version('1.25', '>=')
- 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)