Running Existing Tasks

Difficulty: Intermediate

Time: Approximately 10 minutes

In this exercise you will explore existing tasks, including several tasks that take advantage of Puppet under-the-hood.


Complete the following before you start this lesson:

Inspect Installed Tasks

Bolt is packaged with useful modules and task content.

Run the bolt task show command to view a list of the tasks installed in the project directory.

bolt task show

The result:

facts                              Gather system facts
facts::bash                        Gather system facts using bash
facts::powershell                  Gather system facts using powershell
facts::ruby                        Gather system facts using ruby and facter
package                            Manage and inspect the state of packages
puppet_agent::install              Install the Puppet agent package
puppet_agent::version              Get the version of the Puppet agent package installed. Returns nothing if none present.
puppet_conf                        Inspect puppet agent configuration settings
service                            Manage and inspect the state of services
service::linux                     Manage the state of services (without a puppet agent)
service::windows                   Manage the state of Windows services (without a puppet agent)


Use bolt task show <task-name> to view details and parameters for a specific task.

Use the puppet_agent Module to Install Puppet Agent.

Install puppet agent with the puppet_agent::install task.

bolt task run puppet_agent::install --nodes linux --run-as root

The result:

puppet-agent.x86_64 0:6.0.1-1.el7                                             
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base:
 * extras:
 * updates:
No packages marked for update
Successful on 3 nodes: node1,node2,node3
Ran on 3 nodes in 68.71 seconds

View and Use Parameters For a Specific Task

Run bolt task show package to view the parameters that the package task uses.

bolt task show package

The result:

package - Manage and inspect the state of packages

bolt task run --nodes <node-name> package action=<value> name=<value> version=<value> provider=<value>

- action: Enum[install, status, uninstall, upgrade]
    The operation (install, status, uninstall and upgrade) to perform on the package
- name: String[1]
    The name of the package to be manipulated
- version: Optional[String[1]]
    Version numbers must match the full version to install, including release if the provider uses a release moniker. Ranges or semver patterns are not accepted except for the gem package provider. For example, to install the bash package from the rpm bash-4.1.2-29.el6.x86_64.rpm, use the string '4.1.2-29.el6'.
- provider: Optional[String[1]]
    The provider to use to manage or inspect the package, defaults to the system package manager

built-in module

Using parameters for the package task, check on the status of the bash package:

bolt task run package action=status name=bash --nodes node1

The result:

Started on node1...
Finished on node1:
    "status": "up to date",
    "version": "4.2.46-30.el7"
Successful on 1 node: node1
Ran on 1 node in 3.84 seconds

Using parameters for the package task, install the vim package across all your nodes:

bolt task run package action=install name=vim --nodes linux --run-as root

The result:

Started on node1...
Started on node3...
Started on node2...
Finished on node1:
    "status": "present",
    "version": "2:7.4.160-4.el7"
Finished on node3:
    "status": "installed",
    "version": "2:7.4.160-4.el7"
Finished on node2:
    "status": "installed",
    "version": "2:7.4.160-4.el7"
Successful on 3 nodes: node1,node2,node3
Ran on 3 nodes in 10.03 seconds

More Tips, Tricks and Ideas

See the installing modules documentation to learn how to install external modules. These exercises introduce you to Bolt tasks.

Next Steps

Now that you know how to run existing tasks with Bolt you can move on to:

Writing Plans