---
layout: docs
page_title: change_script Block - Job Specification
description: The "change_script" block configures a script to be run on template re-render.
---

# `change_script` Block

<Placement groups={['job', 'group', 'task', 'template', 'change_script']} />

The `change_script` block allows operators to configure scripts that
will be executed on template change. This block is only used when template
`change_mode` is set to `script`.

```hcl
job "docs" {
  group "example" {
    task "server" {
      template {
        source      = "local/redis.conf.tpl"
        destination = "local/redis.conf"
        change_mode = "script"
        change_script {
          command       = "/bin/foo"
          args          = ["-verbose", "-debug"]
          timeout       = "5s"
          fail_on_error = false
        }
      }
    }
  }
}
```

## `change_script` Parameters

- `command` `(string: "")` - Specifies the full path to a script or executable
  that is to be executed on template change. The command must return exit code 0
  to be considered successful. Path is relative to the driver, e.g., if running
  with a container driver the path must be existing in the container.  This option
  is required if `change_mode` is `script`.

- `args` `(array<string>: [])` - List of arguments that are passed to the script
  that is to be executed on template change.

- `timeout` `(string: "5s")` - Timeout for script execution specified using a
  label suffix like `"30s"` or `"1h"`.

- `fail_on_error` `(bool: false)` - If `true`, Nomad will kill the task if the
  script execution fails. If `false`, script failure will be logged but the task
  will continue uninterrupted.

### Template as a script example

Below is an example of how a script can be embedded in a `data` block of another
`template` block:

```hcl
job "docs" {
  group "example" {
    task "server" {
      template {
        data        = "{{key \"my_key\"}}"
        destination = "local/test"
        change_mode = "script"

        change_script {
          command = "/local/script.sh"
        }
      }

      template {
        data        = <<EOF
#!/usr/bin/env bash
echo "Running change_mode script"
sleep 10
echo "Done"
EOF
        destination = "local/script.sh"
        perms       = "777"
      }
    }
  }
}
```
