Writing Packer Templates: Difference between revisions
Jump to navigation
Jump to search
Line 9: | Line 9: | ||
=Template Variables= | =Template Variables= | ||
{{External|https://www.packer.io/docs/templates/engine.html#template-variables}} | {{External|https://www.packer.io/docs/templates/engine.html#template-variables}} | ||
Template variables are special variables automatically set by Packer at build time. Some builders, provisioners and other components have template variables that are available only for that component. Template variables are recognizable because they're prefixed by a period, such as <code>{ .Name }}<code>. For example, when using the shell provisioner template variables are available to customize the <code>execute_command</code> parameter used to determine how Packer will run the shell command: | Template variables are special variables automatically set by Packer at build time. Some builders, provisioners and other components have template variables that are available only for that component. Template variables are recognizable because they're prefixed by a period, such as <code>{{ .Name }}</code>. For example, when using the shell provisioner template variables are available to customize the <code>execute_command</code> parameter used to determine how Packer will run the shell command: | ||
<syntaxhighlight lang='json'> | <syntaxhighlight lang='json'> | ||
{ | { |
Revision as of 17:38, 15 November 2019
External
Internal
Template User Variables
Template Variables
Template variables are special variables automatically set by Packer at build time. Some builders, provisioners and other components have template variables that are available only for that component. Template variables are recognizable because they're prefixed by a period, such as {{ .Name }}
. For example, when using the shell provisioner template variables are available to customize the execute_command
parameter used to determine how Packer will run the shell command:
{
"provisioners": [
{
"type": "shell",
"execute_command": "{{.Vars}} sudo -E -S bash '{{.Path}}'",
"scripts": [
"scripts/bootstrap.sh"
]
}
]
}
The {{ .Vars }}
and {{ .Path }}
template variables will be replaced with the list of the environment variables and the path to the script to be executed respectively.
Examples
Amazon EBS Template Example
A simple template that produces an Amazon AMI
{
}