Debian Codegraph @

ansible_collections/community/docker/tests/integration/targets/docker_container_info/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 - block:
12 - name: Create random container name
13 ansible.builtin.set_fact:
14 cname: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
15
16 - name: Make sure container is not there
17 community.docker.docker_container:
18 name: "{{ cname }}"
19 state: absent
20 force_kill: true
21
22 - name: Inspect a non-present container
23 community.docker.docker_container_info:
24 name: "{{ cname }}"
25 register: result
26
27 - ansible.builtin.assert:
28 that:
29 - "not result.exists"
30 - "'container' in result"
31 - "result.container is none"
32
33 - name: Make sure container exists
34 community.docker.docker_container:
35 name: "{{ cname }}"
36 image: "{{ docker_test_image_alpine }}"
37 command: '/bin/sh -c "sleep 10m"'
38 state: started
39 force_kill: true
40
41 - name: Inspect a present container
42 community.docker.docker_container_info:
43 name: "{{ cname }}"
44 register: result
45 - name: Dump docker_container_info result
46 ansible.builtin.debug: var=result
47
48 - name: "Comparison: use 'docker inspect'"
49 ansible.builtin.command: docker inspect "{{ cname }}"
50 register: docker_inspect
51 ignore_errors: true
52 - block:
53 - ansible.builtin.set_fact:
54 docker_inspect_result: "{{ docker_inspect.stdout | from_json }}"
55 - name: Dump docker inspect result
56 ansible.builtin.debug: var=docker_inspect_result
57 when: docker_inspect is not failed
58
59 - ansible.builtin.assert:
60 that:
61 - result.exists
62 - "'container' in result"
63 - "result.container is truthy"
64
65 - ansible.builtin.assert:
66 that:
67 - "result.container == docker_inspect_result[0]"
68 when: docker_inspect is not failed
69 - ansible.builtin.assert:
70 that:
71 - "'is too new. Maximum supported API version is' in docker_inspect.stderr"
72 when: docker_inspect is failed
73
74 always:
75 - name: Cleanup
76 community.docker.docker_container:
77 name: "{{ cname }}"
78 state: absent
79 force_kill: true
80
81 when: docker_api_version is version('1.25', '>=')
82
83 - ansible.builtin.fail: msg="Too old docker / docker-py version to run docker_container_info tests!"
84 when: not(docker_api_version is version('1.25', '>=')) and (ansible_facts.distribution != 'CentOS' or ansible_facts.distribution_major_version|int > 6)