Add example of conditional provisioner

to user-variable docs
This commit is contained in:
Marc Abramowitz 2016-01-22 10:38:25 -08:00
parent b7ba9a507d
commit dec48aa9c1
1 changed files with 17 additions and 0 deletions

View File

@ -145,3 +145,20 @@ specified later override a variable set earlier if it has already been set.
And as mentioned above, no matter where a `-var-file` is specified, a `-var`
flag on the command line will always override any variables from a file.
# Recipes
## Making a provisioner step conditional on the value of a variable
There is no specific syntax in Packer templates for making a provisioner
step conditional, depending on the value of a variable. However, you may
be able to do this by referencing the variable within a command that
you execute. For example, here is how to make a `shell-local`
provisioner only run if the `do_nexpose_scan` variable is non-empty.
``` {.javascript}
{
"type": "shell-local",
"command": "if [ ! -z \"{{user `do_nexpose_scan`}}\" ]; then python -u trigger_nexpose_scan.py; fi"
}
```