docker_host_info: allow to list all containers (#538)

* Allow to list all containers.

* Fix typo.
This commit is contained in:
Felix Fontein
2022-12-27 21:39:17 +01:00
committed by GitHub
parent 44b98609fd
commit faa7fef504
3 changed files with 47 additions and 3 deletions
@@ -6,10 +6,11 @@
- name: Create random container/volume name
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:
msg: "Using container name '{{ cname }}' and volume name '{{ vname }}'"
msg: "Using container names '{{ cname }}' and '{{ cname2 }}', and volume name '{{ vname }}'"
- block:
- name: Get info on Docker host
@@ -30,7 +31,7 @@
# * container and volume lists are non-emtpy because of the created objects;
# * image list is non-empty because the image of the container is there;
# * network list is always non-empty (default networks).
- name: Create container
- name: Create running container
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
@@ -41,9 +42,20 @@
state: started
register: container_output
- name: Create running container
docker_container:
image: "{{ docker_test_image_alpine }}"
name: "{{ cname2 }}"
labels:
key2: value2
key3: value3
state: stopped
register: container2_output
- assert:
that:
- container_output is changed
- container2_output is changed
- name: Create a volume
docker_volume:
@@ -108,6 +120,28 @@
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:
containers: true
containers_all: false
containers_filters:
label: key2=value2
register: output
- name: Get info on Docker host and list containers matching filters (single label, all containers)
docker_host_info:
containers: true
containers_all: true
containers_filters:
label: key2=value2
register: output_all
- name: assert one resp. two container is returned
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:
containers: yes