I am creating a puppet bolt plan to install docker on 4 hosts, enable swarm on the first host, and then add the other 3 hosts to that swarm.
My issue is I do not know how to save this section of the yaml to a variable.
steps:
- command: docker swarm init
targets: $firstmanagementnode
Which I need because the output contains a key to allow other hosts to join the swarm later on in the plan
There is an example in Puppet's documentation below, but honestly I can make heads or tails of it
steps:
- name: hostnames
command: hostname -f
targets: $targets
- task: echo
parameters:
message: $hostnames.map |$hostname_result| { $hostname_result['stdout'] }.join(',')
I was able to solve my problem with the yaml and task below:
YAML:
- name: initswarm
command: docker swarm init
targets: $firstmanagementnode
- name: managertoken
command: docker swarm join-token manager
targets: $firstmanagementnode
- name: managersjoin
task: docker_swarm::joinswarm
targets: $managernodes
parameters:
masternode: $managertoken.map |$token_result| { $token_result['stdout'] }.join(',')
description: configure additional manager nodes
task:
#!/bin/bash
$(echo $PT_masternode | grep -o 'docker.*2377')
task json:
{
"description": "joins a docker swarm",
"input_method": "both",
"parameters": {
"masternode": {
"description": "The first master node",
"type": "String"
}
}
}