2018-11-05 17:05:26 +00:00
---
- name : Create random names
set_fact :
cname : "{{ 'ansible-container-%0x' % ((2**32) | random) }}"
nname : "{{ 'ansible-network-%0x' % ((2**32) | random) }}"
vname : "{{ 'ansible-volume-%0x' % ((2**32) | random) }}"
- block :
# Create objects to be pruned
- docker_container :
name : "{{ cname }}"
image : hello-world
state : present
register : container
- docker_network :
name : "{{ nname }}"
state : present
register : network
- docker_volume :
name : "{{ vname }}"
state : present
register : volume
# Prune objects
- docker_prune :
containers : yes
images : yes
networks : yes
volumes : yes
2018-11-19 10:01:40 +00:00
builder_cache : "{{ docker_py_version is version('3.3.0', '>=') }}"
2018-11-05 17:05:26 +00:00
register : result
# Analyze result
- debug : var=result
- assert :
that :
# containers
2019-02-18 13:41:34 +00:00
- container.docker_container.Id in result.containers
2018-11-05 17:05:26 +00:00
- "'containers_space_reclaimed' in result"
# images
- "'images_space_reclaimed' in result"
# networks
2019-02-18 13:41:34 +00:00
- network.docker_network.Name in result.networks
2018-11-05 17:05:26 +00:00
# volumes
2019-02-18 13:41:34 +00:00
- volume.docker_volume.Name in result.volumes
2018-11-05 17:05:26 +00:00
- "'volumes_space_reclaimed' in result"
# builder_cache
- "'builder_cache_space_reclaimed' in result"
# Test with filters
- docker_prune :
images : yes
images_filters :
dangling : true
register : result
- debug : var=result
2018-11-19 10:01:40 +00:00
when : docker_py_version is version('2.1.0', '>=') and docker_api_version is version('1.25', '>=')
- fail : msg="Too old docker / docker-py version to run docker_prune tests!"
when : not(docker_py_version is version('2.1.0', '>=') and docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)