[2.7] docker_swarm_service: don't crash when publish isn't specified (#53262)

* Don't crash when publish isn't specified.

* Add changelog.

* Add validation code.

* Use generic supertype of dict.
pull/53307/head
Felix Fontein 6 years ago committed by Toshio Kuratomi
parent 72f4d1b22b
commit 2f91d399ec

@ -0,0 +1,3 @@
bugfixes:
- "docker_swarm_service - don't crash when ``publish`` is not specified."
- "docker_swarm_service - do basic validation of ``publish`` option if specified (must be list of dicts)."

@ -477,6 +477,7 @@ from ansible.module_utils.docker_common import docker_version
from ansible.module_utils.basic import human_to_bytes from ansible.module_utils.basic import human_to_bytes
from ansible.module_utils._text import to_text from ansible.module_utils._text import to_text
from ansible.module_utils.common._collections_compat import Mapping
try: try:
from distutils.version import LooseVersion from distutils.version import LooseVersion
@ -1055,7 +1056,9 @@ class DockerServiceManager():
msg=('%s parameter supported only with api_version>=%s' msg=('%s parameter supported only with api_version>=%s'
% (pv['param'], pv['min_version']))) % (pv['param'], pv['min_version'])))
for publish_def in self.client.module.params.get('publish', []): for publish_def in params['publish'] or []:
if not isinstance(publish_def, Mapping):
self.client.module.fail_json(msg='The publish option must be provided with a list of dicts!')
if 'mode' in publish_def.keys(): if 'mode' in publish_def.keys():
if LooseVersion(self.client.version()['ApiVersion']) < LooseVersion('1.25'): if LooseVersion(self.client.version()['ApiVersion']) < LooseVersion('1.25'):
self.client.module.fail_json(msg='publish.mode parameter supported only with api_version>=1.25') self.client.module.fail_json(msg='publish.mode parameter supported only with api_version>=1.25')

Loading…
Cancel
Save