Simple orchestration with Puppet Bolt

March 30, 2020 

As discussed in the introductory post one of the use-cases for Puppet Bolt is orchestration - running actions on multiple targets in a certain order, possibly using results of actions or data from some targets on other targets. Orchestration with Bolt plans is quite easy: you just create a plan with multiple TargetSpec parameters, each representing a target or a type of target. A classic example is two or more web servers behind a load balancer. In this case we do something even simpler and just take a fact from a node called "first" and create a file on node "second" that uses the value of that fact in a file.

In this case our inventory.yaml at the root of our control repository (also Boltdir) looks like this:

version: 2
  - name: vagrant
    - ubuntu-1604
    - ubuntu-1804

Both of these nodes are Vagrant VMs. Their SSH connection defaults have been added to ~/.ssh/config in the usual "vagrant ssh-config ubuntu-1604 >> ~/.ssh/config" style. This allows Bolt to connect to them easily.

Our plan is in site/profile/plans/orchestrate.pp and looks like this:

# Demo of simple orchestration
plan profile::orchestrate
  TargetSpec $first,
  TargetSpec $second
  # Prepare nodes for Bolt (install Puppet etc)
  apply_prep([$first, $second])

  # This makes references to "first" a bit easier. If several "first" servers were
  # defined this would refer to the first of them.
  $first_node = get_targets($first)[0]

  # Run "puppet apply" on the "second" server and use a fact from "first"
  apply($second) {
    file { '/':
      ensure  => 'present',
      content => "FQDN of first node: ${first_node.facts['fqdn']}\n",

This plan is targeted to correct nodes by giving both plan parameters a value. As both parameters are of TargetSpec type we don't want or need to use the --target parameter at all, unlike with ad hoc commands:

$ bolt plan run profile::orchestrate first=ubuntu-1604 second=ubuntu-1804 --run-as root
 Starting: plan profile::orchestrate
 Starting: install puppet and gather facts on ubuntu-1604, ubuntu-1804
 Finished: install puppet and gather facts with 0 failures in 8.01 sec
 Starting: apply catalog on ubuntu-1804
 Finished: apply catalog with 0 failures in 9.49 sec
 Finished: plan profile::orchestrate in 17.53 sec
 Plan completed successfully with no result

Nothing seems to have happened. However, if we run an ad hoc command to check the value of / on the second server we see that things have worked as expected:

$ bolt command run "cat /" --target ubuntu-1804
 Started on ubuntu-1804…
 Finished on ubuntu-1804:
     FQDN of first node: ubuntu-1604.local
 Successful on 1 target: ubuntu-1804
 Ran on 1 target in 0.81 sec                 
Samuli Seppänen
Samuli Seppänen
Author archive