Writing plans in the Puppet language
Bolt plans allow you to tie together complex workflows that include multiple tasks, scripts, commands, and even other plans.
Plans written in the Puppet language allow for more sophisticated control flow and better error handling than YAML plans. Puppet plans also allow you to apply blocks of Puppet code to remote targets.
When you’re writing a plan, you can use any combination of Bolt functions or built-in Puppet functions.
Note: For information on how to convert an existing YAML plan to a Puppet plan, see Converting YAML plans to Puppet language plans.
📖 Related information
- For information on using Hiera data in plans, see Using Bolt with Hiera.
Plan location
Bolt content follows the same directory structure as Puppet modules. Bolt loads
downloaded module plans from modules/<MODULE_NAME>/plans/, and local plans
from site-modules/<MODULE_NAME>/plans/.
Put your Bolt plan in your module’s plans directory and give it the .pp
extension. For example, given a plan named my_plan.pp in a module named
my_module, the location of the plan would be
site-modules/my_module/plans/my_plan.pp.
Creating a new project-level Puppet language plan
You can create a new project-level Puppet language plan in your Bolt project using a Bolt command. The command accepts a single argument: the name of the plan. Project-level plans must be namespaced to the project.
*nix shell command
bolt plan new <PLAN NAME> --pp
PowerShell cmdlet
New-BoltPlan -Name <PLAN NAME> -Pp
For example, running bolt plan new myproject::myplan --pp will result in
a directory structure similar to this:
myproject/
├── bolt-project.yaml
└── plans/
└── myplan.pp
Naming plans
The first line of your plan contains the plan name. You use the plan name to call the plan from the Bolt command line, or from other plans.
Plan names are composed of two or more name segments, indicating:
- The name of the module the plan is located in.
- The name of the plan file, without the extension.
- The path within the module, if the plan is in a subdirectory of
./plans.
Each plan name segment must begin with a lowercase letter and:
- Can include lowercase letters.
- Can include digits.
- Can include underscores.
- Must not be a reserved word.
- Must not have the same name as any Puppet data types.
- Namespace segments must match the regular expression:
\A[a-z][a-z0-9_]*\Z.
Note: Avoid giving plans the same names as constructs in the Puppet language. Although plans do not share their namespace with other language constructs, giving plans these names makes your code difficult to read.
For example, given a module called mymodule with a plan defined in
./mymodule/plans/myplan.pp, the plan name is mymodule::myplan. The first
line in myplan.pp would be:
plan mymodule::myplan()
Similarly, to call a plan defined in ./mymodule/plans/service/myplan.pp, you
would use the name, mymodule::service::myplan.
init plans
The plan filename init is special. You reference an init plan using the
module name only. For example, in a module called mymodule, the plan defined
in mymodule/plans/init.pp is the mymodule plan. However, this does not apply
to init plans nested in subdirectories. For example, an init plan at
mymodule/plans/service/init.pp is the mymodule::service::init plan.
For an example of an init plan, see the facts
plan.
Defining plan parameters
After the plan’s name, in parentheses, define any parameters that you want to
pass into your plan as arguments. To define a parameter, use the syntax `