Introduction
This blog will help to understand the scripts in Bolt. Bolt is an orchestration tool to automate the configuration of devices. You can install Bolt on any operating system and automate the servers and applications.

Bolt can be used to deploy applications, debug servers, patch and upgrade systems, or halt and restart services. This blog will guide you on how to load a script in the Bolt and how we can manipulate the scripts in the Bolt.
How to Run a Script in Bolt

The Bolt follows a procedure when you try to run the script in Bolt. First, the script will be copied from the Bolt controller to a temporary directory automatically by the Bolt to the target and runs the script. Also, once it is got executed script is deleted from the temporary directory. The target here is the machine or remote device we are targeting with the help of Bolt.
As long as the proper interpreter has been installed on the target operating system, you can run scripts in any language in Bolt. Also, any scripting language the target is capable of using.
There are a few things you should know to run scripts in Bolt.
- Correct script file reference in command.
- Mention the necessary arguments for the script.
-
Available options in Botl CLI. ( you can check out the official documentation for this).
There are multiple ways in Bolt to refer to the scripts.
- You can use the scripts from particular directories in modules available on the modulepaths like <module>/scripts/scriptname.sh. This is the puppet file reference way. Instead of /scripts, you can also use /files to load the scripts like <module>/files/scriptname.sh, but it is not preferable.
- You can use the relative path from the root Bolt project folder.
- You can also use an absolute file path in Bolt.
Example
Let's demonstrate with the help of the script name image_upgrade.sh it is available in a module named docker_modules. This script will update the image for every Docker container available in the docker-project project.
#!/bin/sh
for x in `docker-projects ps --services |sort`; do
echo "redoing $x"
docker-projects rm -s -f $x
docker-projects pull $x
done
docker-projects up -d --remove-orphans
Image_upgrade.sh contains the above content as a script.
You can run the above script with the command:
bolt script run dockers_modules/scripts/Image_upgrade.sh -t <TARGETS>
1. You can pass arguments as command line like in the below example:
#!/bin/sh
cd $1
for x in `docker-projects ps --services |sort`; do
echo "redoing $x"
docker-projects rm -s -f $x
docker-projects pull $x
done
docker-projects up -d --remove-orphans
In the above script cd $1 is the argument we are passing.
Run the above script with the command:
bolt script run dockers_modules/scripts/Image_upgrade.sh ./docker -t <TARGETS>
2. You can pass arguments as environment variables.
Environment variables are those variables that can affect the way a script is running with their dynamic nature.
#!/bin/sh
if [ -n $Docker_Directory ]
cd $Docker_Directory
fi
for x in `docker-projects ps --services |sort`; do
echo "redoing $x"
docker-projects rm -s -f $x
docker-projects pull $x
done
docker-projects up -d --remove-orphans
The above script has Docker_Directory as an environment variable and will observe the changes in the Docker_Directory and change directories.
You can run the above script with the command:
bolt script run dockers_modules/scripts/Image_upgrade.sh -t <TARGETS> --env-var Docker_Directory=./docker




