docs tweaks
This commit is contained in:
parent
c16354d594
commit
00cc425b84
|
@ -390,7 +390,7 @@ Options:
|
||||||
-parallel-builds=1 Number of builds to run in parallel. 1 disables parallelization. 0 means no limit (Default: 0)
|
-parallel-builds=1 Number of builds to run in parallel. 1 disables parallelization. 0 means no limit (Default: 0)
|
||||||
-timestamp-ui Enable prefixing of each ui output with an RFC3339 timestamp.
|
-timestamp-ui Enable prefixing of each ui output with an RFC3339 timestamp.
|
||||||
-var 'key=value' Variable for templates, can be used multiple times.
|
-var 'key=value' Variable for templates, can be used multiple times.
|
||||||
-var-file=path JSON file containing user variables.
|
-var-file=path JSON or HCL2 file containing user variables.
|
||||||
`
|
`
|
||||||
|
|
||||||
return strings.TrimSpace(helpText)
|
return strings.TrimSpace(helpText)
|
||||||
|
|
|
@ -81,7 +81,7 @@ Usage: packer console [options] [TEMPLATE]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-var 'key=value' Variable for templates, can be used multiple times.
|
-var 'key=value' Variable for templates, can be used multiple times.
|
||||||
-var-file=path JSON file containing user variables. [ Note that even in HCL mode this expects file to contain JSON, a fix is comming soon ]
|
-var-file=path JSON or HCL2 file containing user variables. [ Note that even in HCL mode this expects file to contain JSON, a fix is comming soon ]
|
||||||
`
|
`
|
||||||
|
|
||||||
return strings.TrimSpace(helpText)
|
return strings.TrimSpace(helpText)
|
||||||
|
|
|
@ -92,7 +92,7 @@ Options:
|
||||||
-except=foo,bar,baz Validate all builds other than these.
|
-except=foo,bar,baz Validate all builds other than these.
|
||||||
-only=foo,bar,baz Validate only these builds.
|
-only=foo,bar,baz Validate only these builds.
|
||||||
-var 'key=value' Variable for templates, can be used multiple times.
|
-var 'key=value' Variable for templates, can be used multiple times.
|
||||||
-var-file=path JSON file containing user variables. [ Note that even in HCL mode this expects file to contain JSON, a fix is comming soon ]
|
-var-file=path JSON or HCL2 file containing user variables. [ Note that even in HCL mode this expects file to contain JSON, a fix is comming soon ]
|
||||||
`
|
`
|
||||||
|
|
||||||
return strings.TrimSpace(helpText)
|
return strings.TrimSpace(helpText)
|
||||||
|
|
|
@ -20,7 +20,7 @@ _packer () {
|
||||||
'-parallel=[(false) Disable parallelization. (Default: false)]'
|
'-parallel=[(false) Disable parallelization. (Default: false)]'
|
||||||
'-parallel-builds=[(0) Number of builds to run in parallel. (Defaults to infinite: 0)]'
|
'-parallel-builds=[(0) Number of builds to run in parallel. (Defaults to infinite: 0)]'
|
||||||
'-var[("key=value") Variable for templates, can be used multiple times.]'
|
'-var[("key=value") Variable for templates, can be used multiple times.]'
|
||||||
'-var-file=[(path) JSON file containing user variables.]'
|
'-var-file=[(path) JSON or HCL2 file containing user variables.]'
|
||||||
'(-)*:files:_files -g "*.json"'
|
'(-)*:files:_files -g "*.json"'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ _packer () {
|
||||||
'-except=[(foo,bar,baz) Validate all builds other than these.]'
|
'-except=[(foo,bar,baz) Validate all builds other than these.]'
|
||||||
'-only=[(foo,bar,baz) Validate only these builds.]'
|
'-only=[(foo,bar,baz) Validate only these builds.]'
|
||||||
'-var[("key=value") Variable for templates, can be used multiple times.]'
|
'-var[("key=value") Variable for templates, can be used multiple times.]'
|
||||||
'-var-file=[(path) JSON file containing user variables.]'
|
'-var-file=[(path) JSON or HCL2 file containing user variables.]'
|
||||||
'(-)*:files:_files -g "*.json"'
|
'(-)*:files:_files -g "*.json"'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -72,14 +72,18 @@ locals {
|
||||||
|
|
||||||
This defines several variables within your Packer configuration, each showing
|
This defines several variables within your Packer configuration, each showing
|
||||||
off a different way to set them. The first variable, "weekday", is an empty
|
off a different way to set them. The first variable, "weekday", is an empty
|
||||||
block `{}`. This will work under many simple circumstances, and Packer will
|
block `{}`, without a type or a default.
|
||||||
guess what type the variable should be at runtime.
|
|
||||||
|
|
||||||
However, it's generally best to provide the type in your variable definition,
|
However, it's generally best to provide the type in your variable definition,
|
||||||
as you can see in variable "flavor", which we have given a type of "string",
|
as you can see in variable "flavor", which we have given a type of "string",
|
||||||
and variable "exit_codes", which we have given a type of "list(number)",
|
and variable "exit_codes", which we have given a type of "list(number)",
|
||||||
meaning it is a list/array of numbers.
|
meaning it is a list/array of numbers.
|
||||||
|
|
||||||
|
When a variable is passed from the cli or environment and the variable's type
|
||||||
|
is not set, Packer will expect it to be a string. But if it is passed from a
|
||||||
|
var-file where Packer can interpret HCL properly it can be a slice or any
|
||||||
|
supported type.
|
||||||
|
|
||||||
In addition to setting the type, the "flavor" and "exit_codes" variables also
|
In addition to setting the type, the "flavor" and "exit_codes" variables also
|
||||||
provide a default. If you set a default value, then you don't need to set the
|
provide a default. If you set a default value, then you don't need to set the
|
||||||
variable at run time. Packer will use a provided command-line var,
|
variable at run time. Packer will use a provided command-line var,
|
||||||
|
@ -87,14 +91,17 @@ var-file, or environment var if it exists, but if not Packer will fall back to
|
||||||
this default value.
|
this default value.
|
||||||
|
|
||||||
If you do not set a default value, Packer will fail immediately when you try to
|
If you do not set a default value, Packer will fail immediately when you try to
|
||||||
run a build if you have not provided the missing variable via the command-line,
|
run a `build` if you have not provided the missing variable via the
|
||||||
a var-file, or the environment.
|
command-line, a var-file, or the environment. The `validate`, `inspect` and
|
||||||
|
`console` commands will work, but variables with unknown values will be
|
||||||
|
`<unknown>`.
|
||||||
|
|
||||||
This also defines two locals: `ice_cream_flavor` and `foo`.
|
This also defines two locals: `ice_cream_flavor` and `foo`.
|
||||||
|
|
||||||
-> **Note**: that it is _not_ possible to a variable in the definition of
|
-> **Note**: that it is _not_ possible to reference a variable in the
|
||||||
another variable. But it _is_ possible to use locals and variables in the
|
definition of another variable. But it _is_ possible to use locals and
|
||||||
definition of a local, as shown in the ice_cream_flavor definition.
|
variables in the definition of a local, as shown in the ice_cream_flavor
|
||||||
|
definition.
|
||||||
|
|
||||||
## Using Variables and locals in Configuration
|
## Using Variables and locals in Configuration
|
||||||
|
|
||||||
|
@ -119,19 +126,19 @@ build {
|
||||||
// specialized HCL2 variable syntax. This example shows a combination of
|
// specialized HCL2 variable syntax. This example shows a combination of
|
||||||
// an HCL2 variable and the golang template engines built into the
|
// an HCL2 variable and the golang template engines built into the
|
||||||
// execute_command option
|
// execute_command option
|
||||||
execute_command = ["/bin/sh", "-c", "echo ${var.sudo_password}| {{.Vars}} {{.Script}}"]
|
execute_command = ["/bin/sh", "-c", "echo ${var.sudo_password}| {{.Vars}} {{.Script}}"]
|
||||||
environment_vars = ["HELLO_USER=packeruser", "UUID=${build.PackerRunUUID}"]
|
environment_vars = ["HELLO_USER=packeruser", "UUID=${build.PackerRunUUID}"]
|
||||||
inline = ["echo the Packer run uuid is $UUID"]
|
inline = ["echo the Packer run uuid is $UUID"]
|
||||||
}
|
}
|
||||||
provisioner "shell-local" {
|
provisioner "shell-local" {
|
||||||
inline = ["echo var.flavor is: ${var.flavor}",
|
inline = ["echo var.flavor is: ${var.flavor}",
|
||||||
"echo local.ice_cream_flavor is: ${local.ice_cream_flavor}"]
|
"echo local.ice_cream_flavor is: ${local.ice_cream_flavor}"]
|
||||||
valid_exit_codes = var.exit_codes
|
valid_exit_codes = var.exit_codes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
As you can see in the example, you can acces your variables directly by
|
As you can see in the example, you can access your variables directly by
|
||||||
giving them the `var.` or `local.` prefix. If you want to embed the variables
|
giving them the `var.` or `local.` prefix. If you want to embed the variables
|
||||||
in a string, you can do so with the `${}` HCL interpolation syntax. If you are
|
in a string, you can do so with the `${}` HCL interpolation syntax. If you are
|
||||||
using an option that is a template engine, you still need to use the golang
|
using an option that is a template engine, you still need to use the golang
|
||||||
|
@ -178,7 +185,7 @@ build {
|
||||||
"source.null.example"
|
"source.null.example"
|
||||||
]
|
]
|
||||||
provisioner "shell-local" {
|
provisioner "shell-local" {
|
||||||
inline = ["echo $PIZZA"]
|
inline = ["echo $PIZZA"]
|
||||||
environment_vars = ["PIZZA=${var.pizza}"]
|
environment_vars = ["PIZZA=${var.pizza}"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,7 +213,7 @@ build {
|
||||||
"source.null.example"
|
"source.null.example"
|
||||||
]
|
]
|
||||||
provisioner "shell-local" {
|
provisioner "shell-local" {
|
||||||
inline = ["echo $PIZZA"]
|
inline = ["echo $PIZZA"]
|
||||||
environment_vars = ["PIZZA=${var.pizza}"]
|
environment_vars = ["PIZZA=${var.pizza}"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -238,7 +245,7 @@ contents:
|
||||||
|
|
||||||
```hcl
|
```hcl
|
||||||
sudo_password = "partyparrot"
|
sudo_password = "partyparrot"
|
||||||
weekday = "Sunday"
|
weekday = "Sunday"
|
||||||
```
|
```
|
||||||
|
|
||||||
You tell Packer to use this var file using the `-var-file` command line flag.
|
You tell Packer to use this var file using the `-var-file` command line flag.
|
||||||
|
|
Loading…
Reference in New Issue