From 330e34051fb1b889d6b1f78a023cdac3a2467d2b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 27 Jun 2013 18:23:47 -0400 Subject: [PATCH] website: execute_command example --- .../docs/provisioners/shell.html.markdown | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/website/source/docs/provisioners/shell.html.markdown b/website/source/docs/provisioners/shell.html.markdown index 1abc6f84b..9db34d484 100644 --- a/website/source/docs/provisioners/shell.html.markdown +++ b/website/source/docs/provisioners/shell.html.markdown @@ -55,3 +55,23 @@ Optional parameters: * `remote_path` (string) - The path where the script will be uploaded to in the machine. This defaults to "/tmp/script.sh". This value must be a writable location and any parent directories must already exist. + +## Execute Command Example + +To many new users, the `execute_command` is puzzling. However, it provides +an important function: customization of how the command is executed. The +most common use case for this is dealing with **sudo password prompts**. + +For example, if the default user of an installed operating system is "packer" +and has the password "packer" for sudo usage, then you'll likely want to +change `execute_command` to be: + +``` +"echo 'packer' | sudo -S sh '{{ .Path }}'" +``` + +The `-S` flag tells `sudo` to read the password from stdin, which in this +case is being piped in with the value of "packer". + +By setting the `execute_command` to this, your script(s) can run with +root privileges without worrying about password prompts.