Debian Codegraph @

ansible_collections/community/docker/tests/integration/targets/docker_container/tasks/main.yml

raw
1 ---
2 # Copyright (c) Ansible Project
3 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4 # SPDX-License-Identifier: GPL-3.0-or-later
5
6 ####################################################################
7 # WARNING: These are designed specifically for Ansible tests #
8 # and should not be used as examples of how to write Ansible roles #
9 ####################################################################
10
11 - name: Gather facts on controller
12 ansible.builtin.setup:
13 gather_subset: '!all'
14 delegate_to: localhost
15 delegate_facts: true
16 run_once: true
17
18 - name: Make sure ipaddress is available on controller
19 ansible.builtin.pip:
20 name: ipaddress
21 delegate_to: localhost
22 when: hostvars['localhost'].ansible_facts.python.version.major < 3
23
24 # Create random name prefix (for containers, networks, ...)
25 - name: Create random container name prefix
26 ansible.builtin.set_fact:
27 cname_prefix: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
28 cnames: []
29 inames: []
30 dnetworks: []
31
32 - ansible.builtin.debug:
33 msg: "Using container name prefix {{ cname_prefix }}"
34
35 - name: Retrieve docker host info
36 community.docker.docker_host_info:
37 register: docker_host_info
38
39 # Run the tests
40 - module_defaults:
41 community.general.docker_container:
42 debug: true
43 block:
44 - ansible.builtin.include_tasks: run-test.yml
45 with_fileglob:
46 - "tests/*.yml"
47 loop_control:
48 loop_var: test_name
49
50 always:
51 - name: "Make sure all containers are removed"
52 community.docker.docker_container:
53 name: "{{ item }}"
54 state: absent
55 force_kill: true
56 with_items: "{{ cnames }}"
57 diff: false
58 - name: "Make sure all images are removed"
59 community.docker.docker_image_remove:
60 name: "{{ item }}"
61 with_items: "{{ inames }}"
62 - name: "Make sure all networks are removed"
63 community.docker.docker_network:
64 name: "{{ item }}"
65 state: absent
66 force: true
67 with_items: "{{ dnetworks }}"
68 diff: false
69
70 when: docker_api_version is version('1.25', '>=')
71
72 - ansible.builtin.fail: msg="Too old docker / docker-py version to run all docker_container tests!"
73 when: not(docker_api_version is version('1.25', '>=')) and (ansible_facts.distribution != 'CentOS' or ansible_facts.distribution_major_version|int > 6)