community.docker
community.docker copied to clipboard
Add availability on the community.general.docker_swarm
SUMMARY
The command 'docker swarm join' has option the --availability, but docker_swarm does not. Before node in work up I want check it and have other manipulation with node. Now I use the shell module for add node into swarm.
ISSUE TYPE
- Feature Idea
COMPONENT NAME
docker_swarm
ADDITIONAL INFORMATION
Files identified in the description: None
If these files are inaccurate, please update the component name
section of the description or use the !component
bot command.
Files identified in the description:
If these files are inaccurate, please update the component name
section of the description or use the !component
bot command.
cc @DBendit @WojciechowskiPiotr @akshay196 @chouseknecht @danihodovic @dariko @felixfontein @jwitko @kassiansun @tbouvet click here for bot help
This seems to be an option for joining (looks so from the docker CLI code), but docker-py does not offer it yet (https://docker-py.readthedocs.io/en/stable/api.html#docker.api.swarm.SwarmApiMixin.join_swarm). Interestingly, it is not mentioned in the API docs either (https://docs.docker.com/engine/api/v1.40/#operation/SwarmJoin).
Client code: https://github.com/docker/cli/blob/master/cli/command/swarm/join.go#L66 and https://github.com/docker/cli/blob/master/vendor/github.com/docker/docker/api/types/swarm/swarm.go#L167-L174 Daemon code: https://github.com/moby/moby/blob/master/daemon/cluster/swarm.go#L147-L188
Interestingly, setting availability is not part of an API and low-level API. I think it may be worth opening a request in the Docker project for this.
It looks like the only way now is to call docker_node
to change the availability of the node as a next task after joining the swarm.
I don't see an Issue or PR in docker-py for this feature. I will open one and lets see the developers response.
It looks like the only way now is to call
docker_node
to change the availability of the node as a next task after joining the swarm.
But if the cluster is highloaded or has tune rebalance(cron or other method) new container can run before node is check and ready. Now my task looks like this:
- name: "Add {{ inventory_hostname }} into swarm" shell: > docker swarm join --advertise-addr {{ ansible_host }} --availability pause --data-path-addr {{ ansible_host }} --listen-addr {{ ansible_host }} --token {{ swarm_info.swarm_facts.JoinTokens.Manager }} {{ swarm_manager_ip }}:2377 register: swarm_add changed_when: "'This node is already part of a swarm.' not in swarm_add.stderr or 'This node joined a swarm as a manager.' in swarm_add.stdout" failed_when: "'This node is already part of a swarm.' not in swarm_add.stderr
It looks like the only way now is to call
docker_node
to change the availability of the node as a next task after joining the swarm.But if the cluster is highloaded or has tune rebalance(cron or other method) new container can run before node is check and ready. Now my task looks like this:
I agree this is not a solution, but only a "dirty" workaround of the problem on the playbook level. Also, you must run the task on the manager node which may be another problem on some playbooks. I've opened an issue on the docker-py project, let's see what they say about that.
I also created an issue in moby/moby asking to document this API. I'm not sure it will get implemented in docker-py without being documented.
Reference to issue: https://github.com/moby/moby/issues/41429