I am using ansible community.docker modules to manage a docker swarm cluster. So far the initialization of manager and worker nodes does work great.
Now I try to label nodes in the cluster and use the community.docker.docker_node for that. When I try to label the nodes, I get an error from the node telling me that this module must be run on a manger node.
fatal: [aragorn.m.internal]: FAILED! => {"changed": false, "msg": "Error running docker swarm module: must run on swarm manager node"}
How do I do that? Checked the module syntax and examples but could not get a clue about it.
Whereas swarm is the group of all nodes of the swarm and swarm_labels is a dictionary of labels given as a host variable of the host to set the labels on. Only a few of them are managers.
I tried that already. This will only work if the delegated target is the master node. For all worker nodes this gives an error like:
fatal: [concierge.m.internal -> camina.m.internal]: FAILED! => {"changed": false, "msg": "Failed to update node : 400 Client Error for http+docker://localhost/v1.47/nodes/sxrdnv670whbk2ifo96pw1qrj/update?version=3152: Bad Request (\"invalid JSON: json: cannot unmarshal number into Go struct field NodeSpec.Labels of type string\")"}
Looks like the connection is not made via docker socket but it tries to contact via http.
And the 400er status code means bad request, which means the module does not create a valid request.
Unfortunately the documentation does not give any further hints but only shows the example I used in this post.
The module should be fixed so that it automatically converts non-strings to strings (or warns/fails for things that cannot be converted correctly, like booleans), but fixing the types on your side is of course the better way There’s also always the problem with having 1.10 ending up as 1.1 because it’s treated as a floating point number (Integers are safe though, except if you happen to use hexadecimal or octal encoding, which will be gone by the time when they’re converted back to strings…)