Thanks for the tip.  I am much closer but I'm getting some undesirable 
characters added to the var named "key" I'm setting.


   1. - hosts: swarm-init
   2.   tasks:
   3.     - shell: docker swarm init
   4.     - shell: docker swarm join-token -q manager
   5.       register: manager
   6.     - set_fact:
   7.         manager: "{{ manager.stdout_lines }}"
   8.     - shell: docker swarm join-token -q worker
   9.       register: worker
   10.     - set_fact:
   11.         worker: "{{ worker.stdout_lines }}"
   12. - hosts: swarm-worker
   13.   vars:
   14.     key: "{{ hostvars[groups['swarm-init'][0]]['worker'] }}"
   15.   tasks:
   16.    - shell: "docker swarm join --token {{ key }} {{ swarmmanager }}:2377"


Inventory

   1. [swarm-init]
   2. myhost1
   3.  
   4. [swarm-manager]
   5. myhost1
   6.  
   7. [swarm-worker]
   8. myhost2
   9.  
   10. [swarm-manager:vars]
   11. swarmmanager=myhost1
   12.  
   13. [swarm-worker:vars]
   14. swarmmanager=myhost1


The output:

PLAY ***************************************************************************

TASK [setup] *******************************************************************
ok: [myhost1]

TASK [command] *****************************************************************
changed: [myhost1]

TASK [command] *****************************************************************

changed: [myhost1]

TASK [set_fact] ****************************************************************
ok: [myhost1]

TASK [command] *****************************************************************
changed: [myhost1]

TASK [set_fact] ****************************************************************
ok: [myhost1]

PLAY ***************************************************************************

TASK [setup] *******************************************************************

ok: [myhost2]

TASK [command] *****************************************************************
fatal: [myhost2]: FAILED! => {"changed": true, "cmd": "docker swarm join 
--token 
[u'SWMTKN-1-0lanrq32u7f1v47noxftd1ekpzgipo3noufg7ppox3aooqhmqh-3peerw7aalzg8ko13zrqh6hee']
 myhost1:2377", "delta": "0:00:00.036979", "end": "2016-08-07 20:20:16.500147", 
"failed": true, "rc": 1, "start": "2016-08-07 20:20:16.463168", "stderr": 
"Error response from daemon: invalid join token", "stdout": "", "stdout_lines": 
[], "warnings": []}


PLAY RECAP *********************************************************************
myhost1   : ok=6    changed=3    unreachable=0    failed=0   
myhost2   : ok=1    changed=0    unreachable=0    failed=1   

FATAL: command execution failedhudson.AbortException 
<http://stacktrace.jenkins-ci.org/search?query=hudson.AbortException>: Ansible 
playbook execution failed
        at 
org.jenkinsci.plugins.ansible.AnsiblePlaybookBuilder.perform(AnsiblePlaybookBuilder.java:218)
 
<http://stacktrace.jenkins-ci.org/search/?query=org.jenkinsci.plugins.ansible.AnsiblePlaybookBuilder.perform&entity=method>
        at 
org.jenkinsci.plugins.ansible.AnsiblePlaybookBuilder.perform(AnsiblePlaybookBuilder.java:192)
 
<http://stacktrace.jenkins-ci.org/search/?query=org.jenkinsci.plugins.ansible.AnsiblePlaybookBuilder.perform&entity=method>
        at 
hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:78)
 
<http://stacktrace.jenkins-ci.org/search/?query=hudson.tasks.BuildStepCompatibilityLayer.perform&entity=method>
        at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20) 
<http://stacktrace.jenkins-ci.org/search/?query=hudson.tasks.BuildStepMonitor$1.perform&entity=method>
        at 
hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
 
<http://stacktrace.jenkins-ci.org/search/?query=hudson.model.AbstractBuild$AbstractBuildExecution.perform&entity=method>
        at hudson.model.Build$BuildExecution.build(Build.java:205) 
<http://stacktrace.jenkins-ci.org/search/?query=hudson.model.Build$BuildExecution.build&entity=method>
        at hudson.model.Build$BuildExecution.doRun(Build.java:162) 
<http://stacktrace.jenkins-ci.org/search/?query=hudson.model.Build$BuildExecution.doRun&entity=method>
        at 
hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534) 
<http://stacktrace.jenkins-ci.org/search/?query=hudson.model.AbstractBuild$AbstractBuildExecution.run&entity=method>
        at hudson.model.Run.execute(Run.java:1741) 
<http://stacktrace.jenkins-ci.org/search/?query=hudson.model.Run.execute&entity=method>
        at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43) 
<http://stacktrace.jenkins-ci.org/search/?query=hudson.model.FreeStyleBuild.run&entity=method>
        at hudson.model.ResourceController.execute(ResourceController.java:98) 
<http://stacktrace.jenkins-ci.org/search/?query=hudson.model.ResourceController.execute&entity=method>
        at hudson.model.Executor.run(Executor.java:410) 
<http://stacktrace.jenkins-ci.org/search/?query=hudson.model.Executor.run&entity=method>
ERROR: Ansible playbook execution failed
Notifying upstream projects of job completion
Finished: FAILURE


On Saturday, August 6, 2016 at 11:23:17 PM UTC-5, Stephen Granger wrote:
>
> http://docs.ansible.com/ansible/set_fact_module.html
>
>     - name: set fact from hosts output
>       set_fact:
>        docker_manager: manager.stdout
>        docker_worker: worker.stdout
>
> # you may want to just pick out a line too, see the debug for what you may 
> want
>
>     - debug:
>         var:
>           - worker.stdout_lines
>           - manager.stdout_lines
>
> On 6 August 2016 at 08:15, Tony Owens <[email protected] <javascript:>> 
> wrote:
>
>> I'm looking for some tips on the best way to store a variable 
>> persistently across all hosts or multiple plays.
>>
>> I am attempting to create a docker swarm manager using something similar 
>> to this:
>>
>>
>>    1. - hosts: swarm-init
>>    2. gather_facts: no
>>    3. tasks:
>>    4. - shell: docker swarm init
>>    5. - shell: docker swarm join-token -q manager
>>    6. register: manager
>>    7. - shell: docker swarm join-token -q worker
>>    8. register: worker
>>
>>
>> I would run this play once and don't have that logic built yet but I have 
>> not been able to find a method of storing {{ worker }} in a variable so 
>> that I could join the swarm from another host in another play.  Any advice?
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Ansible Project" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/43c19f78-9572-4af2-8e52-784878805bcc%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/43c19f78-9572-4af2-8e52-784878805bcc%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Steve
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1f9b0ae5-6be7-4b47-8cbc-baf6a84c7844%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to