community.docker/tests/integration/targets/docker_network_info/tasks/main.yml
2025-10-25 10:12:21 +02:00

81 lines
2.7 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 #
####################################################################
- block:
- name: Create random network name
ansible.builtin.set_fact:
nname: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
- name: Make sure network is not there
community.docker.docker_network:
name: "{{ nname }}"
state: absent
force: true
- name: Inspect a non-present network
community.docker.docker_network_info:
name: "{{ nname }}"
register: result
- ansible.builtin.assert:
that:
- "not result.exists"
- "'network' in result"
- "result.network is none"
- name: Make sure network exists
community.docker.docker_network:
name: "{{ nname }}"
state: present
- name: Inspect a present network
community.docker.docker_network_info:
name: "{{ nname }}"
register: result
- name: Dump docker_network_info result
ansible.builtin.debug: var=result
- name: "Comparison: use 'docker network inspect'"
ansible.builtin.command: docker network inspect "{{ nname }}"
register: docker_inspect
ignore_errors: true
- block:
- ansible.builtin.set_fact:
docker_inspect_result: "{{ docker_inspect.stdout | from_json }}"
- name: Dump docker inspect result
ansible.builtin.debug: var=docker_inspect_result
when: docker_inspect is not failed
- name: Cleanup
community.docker.docker_network:
name: "{{ nname }}"
state: absent
force: true
- ansible.builtin.assert:
that:
- result.exists
- "'network' in result"
- "result.network is truthy"
- ansible.builtin.assert:
that:
- "result.network == docker_inspect_result[0]"
when: docker_inspect is not failed
- 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', '>=')
- 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)