mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-23 10:51:24 -07:00
docker_container: fix check mode for container creation (#42380)
* Create copy of HostConfig object before adding it to results. * Create general sanitize function in docker_common. Using it for all return values of docker_container. * Make Python 2.6 compatible.
This commit is contained in:
parent
047fddfe86
commit
fabba43da7
2 changed files with 21 additions and 3 deletions
|
@ -120,6 +120,24 @@ if not HAS_DOCKER_PY:
|
|||
pass
|
||||
|
||||
|
||||
def sanitize_result(data):
|
||||
"""Sanitize data object for return to Ansible.
|
||||
|
||||
When the data object contains types such as docker.types.containers.HostConfig,
|
||||
Ansible will fail when these are returned via exit_json or fail_json.
|
||||
HostConfig is derived from dict, but its constructor requires additional
|
||||
arguments. This function sanitizes data structures by recursively converting
|
||||
everything derived from dict to dict and everything derived from list (and tuple)
|
||||
to a list.
|
||||
"""
|
||||
if isinstance(data, dict):
|
||||
return dict((k, sanitize_result(v)) for k, v in data.items())
|
||||
elif isinstance(data, (list, tuple)):
|
||||
return [sanitize_result(v) for v in data]
|
||||
else:
|
||||
return data
|
||||
|
||||
|
||||
class DockerBaseClass(object):
|
||||
|
||||
def __init__(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue