docker_prune: correctly return 'changed' result (#593)

* Correctly return 'changed' status.

* Extend tests.

* Fix typo.
This commit is contained in:
Felix Fontein
2023-02-24 17:24:16 +01:00
committed by GitHub
parent d0e61097f1
commit 08bfcf7e5f
3 changed files with 52 additions and 1 deletions
@@ -40,7 +40,8 @@
command: docker volume list
# Prune objects
- docker_prune:
- name: Prune everything
docker_prune:
containers: true
images: true
networks: true
@@ -55,6 +56,7 @@
- name: General checks
assert:
that:
- result is changed
# containers
- container.container.Id in result.containers
- "'containers_space_reclaimed' in result"
@@ -81,6 +83,37 @@
- volume.volume.Name not in result.volumes
when: docker_api_version is version('1.42', '>=')
# Prune objects again
- name: Prune everything again (should have no change)
docker_prune:
containers: true
images: true
networks: true
volumes: true
builder_cache: true
register: result
# Analyze result
- name: Show results
debug:
var: result
- name: General checks
assert:
that:
- result is not changed
# containers
- result.containers == []
- result.containers_space_reclaimed == 0
# images
- result.images == []
- result.images_space_reclaimed == 0
# networks
- result.networks == []
# volumes
- result.volumes == []
# builder_cache
- result.builder_cache_space_reclaimed == 0
# Test with filters
- name: Prune with filters
docker_prune:
@@ -110,6 +143,7 @@
- name: Check results
assert:
that:
- result is changed
- volume.volume.Name in result.volumes
- "'volumes_space_reclaimed' in result"