Puppet Bolt Basics: Run Commands, Scripts and Tasks Without an Agent

Puppet Training Course 24 min min read Updated: Nov 17, 2026 Intermediate
Puppet Bolt Basics: Run Commands, Scripts and Tasks Without an Agent
Intermediate Topic 1 of 2

What Is Bolt?

Bolt is an agentless automation tool from the Puppet family. It connects to servers over SSH (Linux) or WinRM (Windows), runs a command, script, task or plan, and prints the result. Nothing has to be installed on the targets except what the connection needs.

Puppet agentBolt
StyleDesired state, runs every 30 minutes by itselfOn demand, runs when you ask
Needs an agentYes, with certificatesNo (SSH or WinRM only)
Best forKeeping configuration correct over timeOne-off actions: patching, restart, health checks, orchestration
LanguagePuppet manifestsCommands, scripts, tasks (any language), plans (YAML or Puppet)
Both together: Many teams use both. The agent keeps servers configured. Bolt triggers actions at the right moment, for example 'drain the node, patch, reboot, check, add back'.

Install Bolt

bash # Use the package for your platform from the Puppet download page, then: sudo dnf install -y puppet-bolt # or apt install puppet-bolt brew install --cask puppetlabs/puppet/puppet-bolt # macOS choco install puppet-bolt # Windows bolt --versio
Version note: Bolt is released separately from the Puppet agent, and new features arrive often. Check bolt --version and the release notes for your version.

First Commands

bash bolt command run 'uptime' --targets web01.example.com --user alice --private-key ~/.ssh/id_ed25519 bolt command run 'systemctl is-active nginx' --targets web01,web02,web03 --user alice bolt command run 'hostname' --targets ssh://web01.example.com:2222 --user alice bolt command run 'Get-Service W32Time' --targets winrm://win01.example.com --user Administrator --password-prompt bolt command run 'whoami' --targets localhost
OptionMeaning
-t, --targetsComma-separated list, group name, or query
-u, --user, --private-key, --password-promptCredentials
--run-as rootSwitch to another user (uses sudo)
--sudo-password-promptAsk for the sudo password
--no-host-key-checkSkip host key verification (lab only)
--format jsonMachine readable output
--concurrency 50How many targets at once (default 100)
--no-verbose, --log-level debugControl logging

Run a Script

bash cat > check_disk.sh <<'EOF' #!/bin/bash echo "Host: $(hostname)" df -h / | tail -1 EOF bolt script run ./check_disk.sh --targets web01,web02 --user alice --run-as root # With arguments bolt script run ./backup.sh --targets db01 --user alice -- /var/lib/mysql /backup

Upload and Download

bash bolt file upload ./app.conf /etc/app/app.conf --targets web01,web02 --user alice --run-as root bolt file download /var/log/app.log ./logs/ --targets web01 --user alice

A Bolt Project

For anything beyond one-liners, create a project directory. Bolt reads its configuration from files in it.

bash mkdir ops-bolt && cd ops-bolt bolt project init ops --modules puppetlabs-package # creates bolt-project.yaml and inventory.yaml
text ops-bolt/ bolt-project.yaml project settings and modules inventory.yaml your targets and groups Puppetfile modules Bolt needs (installed with bolt module install) modules/ your own modules with tasks and plans ops/ tasks/restart_app.sh tasks/restart_app.json plans/patch.pp (or patch.yaml)

Inventory: Targets and Groups

yaml # inventory.yaml --- config: ssh: user: alice private-key: ~/.ssh/id_ed25519 host-key-check: true run-as: root groups: - name: web targets: - web01.example.com - web02.example.com - name: web03.example.com config: ssh: port: 2222 vars: role: webserver env: production - name: db targets: - db01.example.com vars: role: database - name: windows targets: - win01.example.com - win02.example.com config: transport: winrm winrm: user: Administrator password: _plugin: prompt message: 'Windows password' ssl: true - name: all_servers groups: [web, db]
bash bolt inventory show --targets all bolt inventory show --targets web --detail bolt command run 'uptime' --targets web bolt command run 'uptime' --targets 'web,db' bolt command run 'uptime' --targets all_servers --concurrency 10

Dynamic targets from PuppetDB or the cloud

yaml # inventory.yaml with the PuppetDB plugin version: 2 groups: - name: ubuntu_nodes targets: - _plugin: puppetdb query: "inventory[certname] { facts.os.name = 'Ubuntu' }" uri: certname config: puppetdb: server_urls: ['https://puppetdb.example.com:8081'] cacert: ~/.puppetlabs/bolt/ssl/ca.pem

Other plugins read targets from AWS, Azure, GCP, Terraform state, Vagrant and more, so your inventory stays correct without manual edits.

Tasks

A task is a script with a defined interface: it receives parameters as environment variables (PT_name) or JSON on stdin, and returns text or JSON. Tasks can be written in Bash, Python, PowerShell or anything executable. A JSON file describes the task for Bolt, the console and validation.

bash # modules/ops/tasks/restart_app.sh #!/bin/bash service="${PT_service:-nginx}" if systemctl restart "$service"; then echo "{\"service\": \"$service\", \"status\": \"restarted\"}" else echo "{\"_error\": {\"msg\": \"restart failed\", \"kind\": \"ops/restart-failed\"}}" exit 1 fi
json { "description": "Restart a service", "input_method": "environment", "supports_noop": false, "parameters": { "service": { "description": "Name of the service", "type": "Optional[String[1]]" } } }
bash bolt task show # list tasks bolt task show ops::restart_app # help for one task bolt task run ops::restart_app service=nginx --targets web bolt task run package action=status name=openssl --targets web # built-in package task bolt task run service action=restart name=nginx --targets web bolt task run ops::restart_app service=app --targets web --params '{"service":"app"}' --format jso

Built-in Tasks Worth Knowing

TaskUse
packageInstall, upgrade, uninstall, status
servicestart, stop, restart, enable, status
factsCollect facts
rebootReboot and wait for the node
puppet_agent::installInstall the Puppet agent on nodes
puppet_confRead or set Puppet settings
apply_helpers::...Support apply blocks

Apply Puppet Code with Bolt

Bolt can compile Puppet code locally and apply the catalog on remote targets, with no Puppet server.

bash bolt apply manifests/site.pp --targets web bolt apply --execute 'package { "htop": ensure => installed }' --targets web --noop

Output and Results

bash bolt command run 'hostname -f' --targets all --format json | jq '.items[] | {target, status, value: .value.stdout}' bolt command run 'cat /etc/os-release' --targets web --format human bolt command run 'systemctl is-active nginx' --targets web --no-verbose --rerun failure # run again only on failed targets bolt command run 'uptime' --targets web --save-reru

Security Basics

  • Use SSH keys, not passwords, and host-key-check: true
  • Use run-as: root with sudo rules instead of logging in as root
  • Keep passwords out of the inventory using plugins (prompt, env_var, Vault, pkcs7 encrypted values)
  • Limit what the Bolt user can run with sudoers where possible
  • Review tasks like any other code before running on production

Practice Tasks

  1. Install Bolt and run uptime on two lab VMs
  2. Write an inventory with groups web and db and variables
  3. Write a task that prints disk usage with a parameter for the mount point
  4. Run the built-in package task to check the installed version of OpenSSL on all nodes
  5. Use bolt apply --noop to preview a small manifest

Conclusion

Bolt gives agentless, on-demand control. Use an inventory with groups, run commands and scripts, wrap repeatable actions into tasks, and keep the Puppet agent for continuous configuration.

Quick Summary: bolt command/script/task/file; inventory.yaml groups; tasks with PT_ params; apply for manifests; agent for state.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators