Merge pull request #3100 from msabramo/docs_user_variable_example_conditional_provisioner

docs: Add example of conditional provisioner
This commit is contained in:
Chris Bednarski 2016-01-23 21:43:48 -08:00
commit a0b30dcf59
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"
}
```