ansible-dockerswarm icon indicating copy to clipboard operation
ansible-dockerswarm copied to clipboard

Task "Remove labels from swarm node" fails when labels are configured outside this role

Open juanluisbaptiste opened this issue 3 years ago • 1 comments

Hi,

When docker labels are added to nodes of an already provisioned cluster with this role without using the swarm_labels variable in the inventory file, but by for example, adding them manually, the role will fail with the following error:

TASK [atosatto.docker-swarm : Remove labels from swarm node.] ******************
fatal: [swarm_manager_preprod_1]: FAILED! => {"msg": "The conditional check 'item not in swarm_labels' failed. The error was: error while evaluating conditional (item not in swarm_labels): 'swarm_labels' is undefined\n\nThe error appears to be in '/builds/karisma.org.co/pub/ansible/roles/atosatto.docker-swarm/tasks/setup-swarm-labels.yml': line 15, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Remove labels from swarm node.\n  ^ here\n"}

The issue arises because the item variable will be not empty containing the manually added labels, but swarm_labels variable will be empty, as any label has not been configured using that variable, so the when: condition of that task will fail.

This is fixed by also checking that swarm_labels is also defined on that task.

juanluisbaptiste avatar May 20 '21 17:05 juanluisbaptiste

Sorry for the multiple commits, I had to do some reabsing to have this change in its own branch so it could be commited to a PR containing this single fix.

juanluisbaptiste avatar May 20 '21 17:05 juanluisbaptiste