Skip to content

Commit

Permalink
Fix handling of lists for filters.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein committed Sep 17, 2024
1 parent 0e492c5 commit fd99171
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/966-prune-filters.yml
Original file line number Diff line number Diff line change
@@ -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)."
10 changes: 5 additions & 5 deletions plugins/modules/docker_prune.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,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)
params = {'filters': convert_filters(filters)}
res = client.post_to_json('/containers/prune', params=params)
result['containers'] = res.get('ContainersDeleted') or []
Expand All @@ -293,7 +293,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)
params = {'filters': convert_filters(filters)}
res = client.post_to_json('/images/prune', params=params)
result['images'] = res.get('ImagesDeleted') or []
Expand All @@ -302,15 +302,15 @@ 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)
params = {'filters': convert_filters(filters)}
res = client.post_to_json('/networks/prune', params=params)
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)
params = {'filters': convert_filters(filters)}
res = client.post_to_json('/volumes/prune', params=params)
result['volumes'] = res.get('VolumesDeleted') or []
Expand All @@ -319,7 +319,7 @@ def main():
changed = True

if client.module.params['builder_cache']:
filters = clean_dict_booleans_for_docker_api(client.module.params.get('builder_cache_filters'))
filters = clean_dict_booleans_for_docker_api(client.module.params.get('builder_cache_filters'), allow_sequences=True)
params = {'filters': convert_filters(filters)}
if client.module.params.get('builder_cache_all'):
params['all'] = 'true'
Expand Down

0 comments on commit fd99171

Please sign in to comment.