For a long time now we've been advising against the use of provisioners, but our documentation for them is pretty prominent on the website in comparision to the better alternatives, and so it's little surprise that many users end up making significant use of them. Although in the longer term a change to our information architecture would probably address this even better, this is an attempt to be explicit about the downsides of using provisioners and to prominently describe the alternatives that are available for common use-cases, along with some reasons why we consider them to be better. I took the unusual step here of directly linking to specific provider documentation pages about the alternatives, even though we normally try to keep the core documentation provider-agnostic, because otherwise that information tends to be rather buried in the provider documentation and thus the reader would be reasonable to use provisioners just because we're not giving specific enough alternative recommendations.
2.4 KiB
layout | page_title | sidebar_current | description |
---|---|---|---|
docs | Provisioner: remote-exec | docs-provisioners-remote | 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. |
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
provisioner instead. The remote-exec
provisioner supports both ssh
and winrm
type connections.
-> Note: Provisioners should only be used as a last resort. For most common situations there are better alternatives. For more information, see the main Provisioners page.
Example usage
resource "aws_instance" "web" {
# ...
provisioner "remote-exec" {
inline = [
"puppet apply",
"consul join ${aws_instance.web.private_ip}",
]
}
}
Argument Reference
The following arguments are supported:
-
inline
- This is a list of command strings. They are executed in the order they are provided. This cannot be provided withscript
orscripts
. -
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 withinline
orscripts
. -
scripts
- This is a list of paths (relative or absolute) to local scripts that will be copied to the remote resource and then executed. They are executed in the order they are provided. This cannot be provided withinline
orscript
.
Script Arguments
You cannot pass any arguments to scripts using the script
or
scripts
arguments to this provisioner. If you want to specify arguments,
upload the script with the
file provisioner
and then use inline
to call it. Example:
resource "aws_instance" "web" {
# ...
provisioner "file" {
source = "script.sh"
destination = "/tmp/script.sh"
}
provisioner "remote-exec" {
inline = [
"chmod +x /tmp/script.sh",
"/tmp/script.sh args",
]
}
}