docker_node: labels operation fails when parameter 'labels' is None (#52662)

* docker_node: Fix for situation where labels parameter is None

* docker_node: Fix for situation where labels parameter is None and labels are not removed
This commit is contained in:
Piotr Wojciechowski 2019-02-20 22:04:42 +01:00 committed by ansibot
parent 6f91bccf78
commit 67f14772b1

View file

@ -229,15 +229,20 @@ class SwarmNodeManager(DockerBaseClass):
if self.parameters.labels_to_remove is not None:
for key in self.parameters.labels_to_remove:
if not self.parameters.labels.get(key):
if self.parameters.labels is not None:
if not self.parameters.labels.get(key):
if node_spec['Labels'].get(key):
node_spec['Labels'].pop(key)
changed = True
else:
self.client.module.warn(
"Label '%s' listed both in 'labels' and 'labels_to_remove'. "
"Keeping the assigned label value."
% to_native(key))
else:
if node_spec['Labels'].get(key):
node_spec['Labels'].pop(key)
changed = True
else:
self.client.module.warn(
"Label '%s' listed both in 'labels' and 'labels_to_remove'. "
"Keeping the assigned label value."
% to_native(key))
if changed is True:
if not self.check_mode: