1---
2layout: "language"
3page_title: "Provisioner: remote-exec"
4sidebar_current: "docs-provisioners-remote"
5description: |-
6  The `remote-exec` provisioner invokes a script on a remote resource after it is created. This can be used to run a configuration management tool, bootstrap into a cluster, etc. To invoke a local process, see the `local-exec` provisioner instead. The `remote-exec` provisioner supports both `ssh` and `winrm` type connections.
7---
8
9# remote-exec Provisioner
10
11The `remote-exec` provisioner invokes a script on a remote resource after it
12is created. This can be used to run a configuration management tool, bootstrap
13into a cluster, etc. To invoke a local process, see the `local-exec`
14[provisioner](/docs/language/resources/provisioners/local-exec.html) instead. The `remote-exec`
15provisioner supports both `ssh` and `winrm` type [connections](/docs/language/resources/provisioners/connection.html).
16
17-> **Note:** Provisioners should only be used as a last resort. For most
18common situations there are better alternatives. For more information, see
19[the main Provisioners page](./).
20
21## Example usage
22
23```hcl
24resource "aws_instance" "web" {
25  # ...
26
27  provisioner "remote-exec" {
28    inline = [
29      "puppet apply",
30      "consul join ${aws_instance.web.private_ip}",
31    ]
32  }
33}
34```
35
36## Argument Reference
37
38The following arguments are supported:
39
40* `inline` - This is a list of command strings. They are executed in the order
41  they are provided. This cannot be provided with `script` or `scripts`.
42
43* `script` - This is a path (relative or absolute) to a local script that will
44  be copied to the remote resource and then executed. This cannot be provided
45  with `inline` or `scripts`.
46
47* `scripts` - This is a list of paths (relative or absolute) to local scripts
48  that will be copied to the remote resource and then executed. They are executed
49  in the order they are provided. This cannot be provided with `inline` or `script`.
50
51-> **Note:** Since `inline` is implemented by concatenating commands into a script, [`on_failure`](/docs/language/resources/provisioners/syntax.html#failure-behavior) applies only to the final command in the list. In particular, with `on_failure = fail` (the default behaviour) earlier commands will be allowed to fail, and later commands will also execute. If this behaviour is not desired, consider using `"set -o errexit"` as the first command.
52
53## Script Arguments
54
55You cannot pass any arguments to scripts using the `script` or
56`scripts` arguments to this provisioner. If you want to specify arguments,
57upload the script with the
58[file provisioner](/docs/language/resources/provisioners/file.html)
59and then use `inline` to call it. Example:
60
61```hcl
62resource "aws_instance" "web" {
63  # ...
64
65  provisioner "file" {
66    source      = "script.sh"
67    destination = "/tmp/script.sh"
68  }
69
70  provisioner "remote-exec" {
71    inline = [
72      "chmod +x /tmp/script.sh",
73      "/tmp/script.sh args",
74    ]
75  }
76}
77```
78