2014-07-23 18:40:15 +02:00
---
2021-12-15 03:41:17 +01:00
page_title: 'Provisioner: remote-exec'
description: >-
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.
2014-07-23 18:40:15 +02:00
---
# remote-exec Provisioner
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`
2021-12-15 03:41:17 +01:00
[provisioner](/language/resources/provisioners/local-exec) instead. The `remote-exec`
provisioner requires a [connection](/language/resources/provisioners/connection)
2021-05-03 00:14:10 +02:00
and supports both `ssh` and `winrm`.
2014-07-23 18:40:15 +02:00
2019-09-06 00:50:04 +02:00
-> **Note:** Provisioners should only be used as a last resort. For most
common situations there are better alternatives. For more information, see
2021-12-15 03:41:17 +01:00
[the main Provisioners page](/language/resources/provisioners).
2014-07-23 18:40:15 +02:00
## Example usage
2017-04-05 17:29:27 +02:00
```hcl
2014-07-23 18:40:15 +02:00
resource "aws_instance" "web" {
2017-02-18 23:48:50 +01:00
# ...
2017-04-05 17:29:27 +02:00
2021-05-03 00:14:10 +02:00
# Establishes connection to be used by all
# generic remote provisioners (i.e. file/remote-exec)
connection {
type = "ssh"
user = "root"
password = var.root_password
host = self.public_ip
}
2017-02-18 23:48:50 +01:00
provisioner "remote-exec" {
inline = [
"puppet apply",
"consul join ${aws_instance.web.private_ip}",
]
}
2014-07-23 18:40:15 +02:00
}
```
## Argument Reference
2014-07-23 21:14:31 +02:00
The following arguments are supported:
2014-07-23 18:40:15 +02:00
2015-01-14 18:28:25 +01:00
* `inline` - This is a list of command strings. They are executed in the order
2014-07-23 18:40:15 +02:00
they are provided. This cannot be provided with `script` or `scripts`.
* `script` - This is a path (relative or absolute) to a local script that will
be copied to the remote resource and then executed. This cannot be provided
with `inline` or `scripts`.
2015-01-14 18:28:25 +01:00
* `scripts` - This is a list of paths (relative or absolute) to local scripts
2014-07-23 18:40:15 +02:00
that will be copied to the remote resource and then executed. They are executed
in the order they are provided. This cannot be provided with `inline` or `script`.
2021-12-15 03:41:17 +01:00
-> **Note:** Since `inline` is implemented by concatenating commands into a script, [`on_failure`](/language/resources/provisioners/syntax#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.
2021-02-19 18:56:48 +01:00
2015-04-22 09:03:38 +02:00
## Script Arguments
You cannot pass any arguments to scripts using the `script` or
2015-04-23 00:00:16 +02:00
`scripts` arguments to this provisioner. If you want to specify arguments,
2015-04-22 09:03:38 +02:00
upload the script with the
2021-12-15 03:41:17 +01:00
[file provisioner](/language/resources/provisioners/file)
2015-04-22 09:03:38 +02:00
and then use `inline` to call it. Example:
2017-04-05 17:29:27 +02:00
```hcl
2015-04-22 09:03:38 +02:00
resource "aws_instance" "web" {
2017-02-18 23:48:50 +01:00
# ...
2015-04-22 09:03:38 +02:00
2017-02-18 23:48:50 +01:00
provisioner "file" {
source = "script.sh"
destination = "/tmp/script.sh"
}
2015-04-22 09:03:38 +02:00
2017-02-18 23:48:50 +01:00
provisioner "remote-exec" {
inline = [
"chmod +x /tmp/script.sh",
"/tmp/script.sh args",
]
}
2015-04-22 09:03:38 +02:00
}
```