Skip to content

Instantly share code, notes, and snippets.

@MikaelSmith
Last active November 12, 2018 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikaelSmith/11e9d96d33d40103bbee63933c0f2caf to your computer and use it in GitHub Desktop.
Save MikaelSmith/11e9d96d33d40103bbee63933c0f2caf to your computer and use it in GitHub Desktop.
Install and bootstrap Docker Swarm using Bolt + the Puppet Docker module
plan examples::swarm(TargetSpec $managers, TargetSpec $workers) {
$hosts = [$managers, $workers]
$hosts.apply_prep
apply($hosts) {
include 'docker'
}
# Initialize the swarm on a single manager.
$targets = get_targets($managers)
$master = $targets[0]
$init_result = run_command('docker swarm init', $master, _catch_errors => true)
# Allow init to fail in case we're running it again. Log the result.
notice($init_result)
$manager_token = run_command('docker swarm join-token manager --quiet', $master).first['stdout'].chomp
$mgr_result = run_command("docker swarm join --token ${manager_token} ${$master.host}:2377", $targets[1,-1], _catch_errors => true)
notice($mgr_result)
$worker_token = run_command('docker swarm join-token worker --quiet', $master).first['stdout'].chomp
return run_command("docker swarm join --token ${worker_token} ${$master.host}:2377", $workers)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment