mirror of
https://github.com/ansible-collections/community.docker.git
synced 2025-12-15 11:32:05 +00:00
* Improve docs.
* Fix handling of lists for filters.
(cherry picked from commit 3802e424d9)
This commit is contained in:
parent
3a5e6006bc
commit
422d51c480
3
changelogs/fragments/966-prune-filters.yml
Normal file
3
changelogs/fragments/966-prune-filters.yml
Normal file
@ -0,0 +1,3 @@
|
||||
bugfixes:
|
||||
- "docker_prune - fix handling of lists for the filter options
|
||||
(https://github.com/ansible-collections/community.docker/issues/961, https://github.com/ansible-collections/community.docker/pull/966)."
|
||||
@ -96,6 +96,22 @@ EXAMPLES = '''
|
||||
# only consider containers created more than 24 hours ago
|
||||
until: 24h
|
||||
|
||||
- name: Prune containers with labels
|
||||
community.docker.docker_prune:
|
||||
containers: true
|
||||
containers_filters:
|
||||
# Prune containers whose "foo" label has value "bar", and
|
||||
# whose "bam" label has value "baz". If you only want to
|
||||
# compare one label, you can provide it as a string instead
|
||||
# of a list with one element.
|
||||
label:
|
||||
- foo=bar
|
||||
- bam=baz
|
||||
# Prune containers whose label "bar" does *not* have value
|
||||
# "baz". If you want to avoid more than one label, you can
|
||||
# provide a list of multiple label-value pairs.
|
||||
"label!": bar=baz
|
||||
|
||||
- name: Prune everything
|
||||
community.docker.docker_prune:
|
||||
containers: true
|
||||
@ -234,7 +250,7 @@ def main():
|
||||
changed = False
|
||||
|
||||
if client.module.params['containers']:
|
||||
filters = clean_dict_booleans_for_docker_api(client.module.params.get('containers_filters'))
|
||||
filters = clean_dict_booleans_for_docker_api(client.module.params.get('containers_filters'), allow_sequences=True)
|
||||
res = client.prune_containers(filters=filters)
|
||||
result['containers'] = res.get('ContainersDeleted') or []
|
||||
result['containers_space_reclaimed'] = res['SpaceReclaimed']
|
||||
@ -242,7 +258,7 @@ def main():
|
||||
changed = True
|
||||
|
||||
if client.module.params['images']:
|
||||
filters = clean_dict_booleans_for_docker_api(client.module.params.get('images_filters'))
|
||||
filters = clean_dict_booleans_for_docker_api(client.module.params.get('images_filters'), allow_sequences=True)
|
||||
res = client.prune_images(filters=filters)
|
||||
result['images'] = res.get('ImagesDeleted') or []
|
||||
result['images_space_reclaimed'] = res['SpaceReclaimed']
|
||||
@ -250,14 +266,14 @@ def main():
|
||||
changed = True
|
||||
|
||||
if client.module.params['networks']:
|
||||
filters = clean_dict_booleans_for_docker_api(client.module.params.get('networks_filters'))
|
||||
filters = clean_dict_booleans_for_docker_api(client.module.params.get('networks_filters'), allow_sequences=True)
|
||||
res = client.prune_networks(filters=filters)
|
||||
result['networks'] = res.get('NetworksDeleted') or []
|
||||
if result['networks']:
|
||||
changed = True
|
||||
|
||||
if client.module.params['volumes']:
|
||||
filters = clean_dict_booleans_for_docker_api(client.module.params.get('volumes_filters'))
|
||||
filters = clean_dict_booleans_for_docker_api(client.module.params.get('volumes_filters'), allow_sequences=True)
|
||||
res = client.prune_volumes(filters=filters)
|
||||
result['volumes'] = res.get('VolumesDeleted') or []
|
||||
result['volumes_space_reclaimed'] = res['SpaceReclaimed']
|
||||
|
||||
Loading…
Reference in New Issue
Block a user