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
pull/52676/head
Piotr Wojciechowski 6 years ago committed by ansibot
parent 6f91bccf78
commit 67f14772b1

@ -229,6 +229,7 @@ class SwarmNodeManager(DockerBaseClass):
if self.parameters.labels_to_remove is not None:
for key in self.parameters.labels_to_remove:
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)
@ -238,6 +239,10 @@ class SwarmNodeManager(DockerBaseClass):
"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
if changed is True:
if not self.check_mode:

Loading…
Cancel
Save