> ## Documentation Index
> Fetch the complete documentation index at: https://rackdog.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Provisioning Scripts

> Run your own setup scripts during server provisioning

Provisioning scripts let you save small setup scripts in your Rackdog organization and run them when a server is installed or reinstalled.
Use them for setups you repeat often: installing packages, adding agents, creating users, writing config, or registering the server with your own tooling.

Scripts are saved at the organization level. When you select a script for a server, Rackdog copies its content into that provisioning run.
If you edit or delete the saved script later, already queued installs will still use the copied version.

## How it works

1. Create a saved script.
2. Select one or more scripts when ordering, provisioning, or reinstalling a server.
3. Rackdog records the selected scripts and their order for that install.
4. On supported Linux and Windows templates, each script runs on first boot.

If no scripts are selected, provisioning continues normally.

## Requirements

* Linux scripts use Bash by default. To use another interpreter, start the script with `#!/usr/bin/python3`.
* Windows scripts run with PowerShell.
* Script content can be up to 1500 characters.
* Script names can be up to 100 characters.
* Linux scripts run as root. Windows scripts run as Administrator.
* Creating, updating, or deleting scripts requires organization admin access.
* Selecting the same script twice in one request is rejected.
* Scripts do not run on Custom iPXE installs.

## Create a script

Use the public API to create a saved script:

```http theme={null}
POST /v1/servers/provisioning-scripts
```

```json theme={null}
{
  "name": "base packages",
  "description": "Install packages we expect on every server",
  "content": "#!/usr/bin/env bash\nset -e\napt-get update\napt-get install -y htop curl"
}
```

The response includes the script ID and `contentSha256`. Use the ID when selecting the script for a server.

## Select scripts for an install

Add `provisioningScripts` to an order, provisioning, or reinstall request:

```json theme={null}
{
  "provisioningScripts": [
    {
      "scriptId": "00000000-0000-0000-0000-000000000000"
    },
    {
      "scriptId": "11111111-1111-1111-1111-111111111111"
    }
  ]
}
```

Scripts run in the order listed in `provisioningScripts`.
If a script exits non-zero, Rackdog stops running the remaining scripts and does not roll the install back.

Script output and errors are written to the server:

* Linux: `/var/log/rackdog/provisioning.log`
* Windows: `C:\ProgramData\Rackdog\provisioning.log`

## Good habits

* Provisioning scripts are best for small bootstrap tasks.
  * For larger setup flows, use a provisioning script to set up your preferred configuration management tool.
* Avoid putting long-lived secrets directly in script content.
* Test on a non-production server before using a script across a fleet.
