SlickNik commented on a change in pull request #278: Fixes #268: Setup fails 
when swarmmanager enabled
URL: https://github.com/apache/fluo-muchos/pull/278#discussion_r320103606
 
 

 ##########
 File path: ansible/docker.yml
 ##########
 @@ -48,5 +48,5 @@
       changed_when: "'active' not in swarm_status.stdout_lines"
     - name: join worker to swarm
       shell: >
-        docker swarm join --token={{ swarm_token }} {{ manager_ip }}:2377
+        docker swarm leave || true && docker swarm join --token={{ 
swarm_token_stdout }} {{ manager_ip }}:2377
 
 Review comment:
   `docker swarm join` doesn't have a `--force` flag, and errors out if the 
node is already part of a swarm (so subsequent runs of the ansible state fail 
since this isn't idempotent). To make this idempotent, we issue a `leave` 
followed by a `join`. However `leave` fails with a non-zero exit code when the 
node isn't already part of a swarm failing the execution of the entire shell 
section. The `|| true` here basically tells the shell to ignore the exit code 
of `docker swarm leave` and continue executing the rest. `;` wouldn't work here 
since it just joins the two commands together, and the shell still errors when 
the first command before the `;` exits with a non-zero exit code. The other 
alternative here would be to explicitly disable the shell's exit code checking 
for the `docker swarm leave` command (i.e. something like `set +e; docker swarm 
leave; set -e; ...`), but I slightly prefer the `|| true` variant for the sake 
of brevity.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to