mirror of https://github.com/hashicorp/packer
commit
fe6077fc85
@ -1,11 +0,0 @@
|
||||
---
|
||||
page_title: Tips and Tricks
|
||||
description: |-
|
||||
The guides stored in this section are miscellanious tips and tricks that might
|
||||
make your experience of using Packer easier
|
||||
---
|
||||
|
||||
# Tips and Tricks
|
||||
|
||||
Click the sidebar navigation to check out the miscellaneous guides we have for
|
||||
making your life with Packer just a bit easier.
|
||||
@ -1,84 +0,0 @@
|
||||
---
|
||||
page_title: Using the isotime template function - Guides
|
||||
description: |-
|
||||
It can be a bit confusing to figure out how to format your isotime using the
|
||||
golang reference date string. Here is a small guide and some examples.
|
||||
---
|
||||
|
||||
# Using the Isotime template function with a format string
|
||||
|
||||
The way you format isotime in golang is a bit nontraditional compared to how
|
||||
you may be used to formatting datetime strings.
|
||||
|
||||
Full docs and examples for the golang time formatting function can be found
|
||||
[here](https://golang.org/pkg/time/#example_Time_Format)
|
||||
|
||||
However, the formatting basics are worth describing here. From the [golang docs](https://golang.org/pkg/time/#pkg-constants):
|
||||
|
||||
> These are predefined layouts for use in Time.Format and time.Parse. The
|
||||
> reference time used in the layouts is the specific time:
|
||||
>
|
||||
> Mon Jan 2 15:04:05 MST 2006
|
||||
>
|
||||
> which is Unix time 1136239445. Since MST is GMT-0700, the reference time
|
||||
> can be thought of as
|
||||
>
|
||||
> 01/02 03:04:05PM '06 -0700
|
||||
>
|
||||
> To define your own format, write down what the reference time would look like
|
||||
> formatted your way; see the values of constants like ANSIC, StampMicro or
|
||||
> Kitchen for examples. The model is to demonstrate what the reference time
|
||||
> looks like so that the Format and Parse methods can apply the same
|
||||
> transformation to a general time value.
|
||||
|
||||
So what does that look like in a Packer template function?
|
||||
|
||||
```json
|
||||
{
|
||||
"variables": {
|
||||
"myvar": "packer-{{isotime \"2006-01-02 03:04:05\"}}"
|
||||
},
|
||||
"builders": [
|
||||
{
|
||||
"type": "null",
|
||||
"communicator": "none"
|
||||
}
|
||||
],
|
||||
"provisioners": [
|
||||
{
|
||||
"type": "shell-local",
|
||||
"inline": ["echo {{ user `myvar`}}"]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
You can switch out the variables section above with the following examples to
|
||||
get different timestamps:
|
||||
|
||||
Date only, not time:
|
||||
|
||||
```json
|
||||
"variables":
|
||||
{
|
||||
"myvar": "packer-{{isotime \"2006-01-02\"}}"
|
||||
}
|
||||
```
|
||||
|
||||
A timestamp down to the millisecond:
|
||||
|
||||
```json
|
||||
"variables":
|
||||
{
|
||||
"myvar": "packer-{{isotime \"Jan-_2-15:04:05.000\"}}"
|
||||
}
|
||||
```
|
||||
|
||||
Or just the time as it would appear on a digital clock:
|
||||
|
||||
```json
|
||||
"variables":
|
||||
{
|
||||
"myvar": "packer-{{isotime \"3:04PM\"}}"
|
||||
}
|
||||
```
|
||||
@ -1,75 +0,0 @@
|
||||
---
|
||||
page_title: Use jq and Packer to comment your templates - Guides
|
||||
description: |-
|
||||
You can add detailed comments beyond the root-level underscore-prefixed field
|
||||
supported by Packer, and remove them using jq.
|
||||
---
|
||||
|
||||
# How to use jq to strip unsupported comments from a Packer template
|
||||
|
||||
-> **Note:** Packer supports HCL2 from version 1.6.0, the Hashicorp Configuration
|
||||
Language allows to comment directly in template files. Consider upgrading your
|
||||
JSON template to HCL2 using the `packer hcl2_upgrade` command.
|
||||
|
||||
One of the biggest complaints we get about Packer is that JSON doesn't use comments.
|
||||
For Packer JSON templates, you can add detailed comments beyond the root-level underscore-prefixed field supported by Packer, and remove them using jq.
|
||||
|
||||
Let's say we have a file named `commented_template.json`
|
||||
|
||||
```json
|
||||
{
|
||||
"_comment": ["this is", "a multi-line", "comment"],
|
||||
"builders": [
|
||||
{
|
||||
"_comment": "this is a comment inside a builder",
|
||||
"type": "null",
|
||||
"communicator": "none"
|
||||
}
|
||||
],
|
||||
"_comment": "this is a root level comment",
|
||||
"provisioners": [
|
||||
{
|
||||
"_comment": "this is a different comment",
|
||||
"type": "shell",
|
||||
"_comment": "this is yet another comment",
|
||||
"inline": ["echo hellooooo"]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
```shell-session
|
||||
$ jq 'walk(if type == "object" then del(._comment) else . end)' commented_template.json > uncommented_template.json
|
||||
```
|
||||
|
||||
will produce a new file containing:
|
||||
|
||||
```json
|
||||
{
|
||||
"builders": [
|
||||
{
|
||||
"type": "null",
|
||||
"communicator": "none"
|
||||
}
|
||||
],
|
||||
"provisioners": [
|
||||
{
|
||||
"type": "shell",
|
||||
"inline": ["echo hellooooo"]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Once you've got your uncommented file, you can call `packer build` on it like
|
||||
you normally would.
|
||||
|
||||
## The walk function
|
||||
|
||||
If your install of jq does not have the walk function and you get an error like
|
||||
|
||||
```text
|
||||
jq: error: walk/1 is not defined at <top-level>,
|
||||
```
|
||||
|
||||
You can create a file `~/.jq` and add the [walk function](https://github.com/stedolan/jq/blob/ad9fc9f559e78a764aac20f669f23cdd020cd943/src/builtin.jq#L255-L262) to it by hand.
|
||||
@ -1,64 +0,0 @@
|
||||
---
|
||||
page_title: Convert Veewee Definitions to Packer Templates - Guides
|
||||
description: |-
|
||||
If you are or were a user of Veewee, then there is an official tool called
|
||||
veewee-to-packer that will convert your Veewee definition into an equivalent
|
||||
Packer template. Even if you're not a Veewee user, Veewee has a large library
|
||||
of templates that can be readily used with Packer by simply converting them.
|
||||
---
|
||||
|
||||
# Veewee-to-Packer
|
||||
|
||||
If you are or were a user of [Veewee](https://github.com/jedi4ever/veewee), then
|
||||
there is an official tool called
|
||||
[veewee-to-packer](https://github.com/mitchellh/veewee-to-packer) that will
|
||||
convert your Veewee definition into an equivalent Packer template. Even if
|
||||
you're not a Veewee user, Veewee has a [large
|
||||
library](https://github.com/jedi4ever/veewee/tree/master/templates) of templates
|
||||
that can be readily used with Packer by simply converting them.
|
||||
|
||||
## Installation and Usage
|
||||
|
||||
Since Veewee itself is a Ruby project, so too is the veewee-to-packer
|
||||
application so that it can read the Veewee configurations. Install it using
|
||||
RubyGems:
|
||||
|
||||
```shell-session
|
||||
$ gem install veewee-to-packer
|
||||
# ...
|
||||
```
|
||||
|
||||
Once installed, just point `veewee-to-packer` at the `definition.rb` file of any
|
||||
template. The converter will output any warnings or messages about the conversion.
|
||||
The example below converts a CentOS template:
|
||||
|
||||
```shell-session
|
||||
$ veewee-to-packer templates/CentOS-6.4/definition.rb
|
||||
Success! Your Veewee definition was converted to a Packer
|
||||
template! The template can be found in the `template.json` file
|
||||
in the output directory: output
|
||||
|
||||
Please be sure to run `packer validate` against the new template
|
||||
to verify settings are correct. Be sure to `cd` into the directory
|
||||
first, since the template has relative paths that expect you to
|
||||
use it from the same working directory.
|
||||
```
|
||||
|
||||
**_Voila!_** By default, `veewee-to-packer` will output a template that contains
|
||||
a builder for both VirtualBox and VMware. You can use the `-only` flag on
|
||||
`packer build` to only build one of them. Otherwise you can use the `--builder`
|
||||
flag on `veewee-to-packer` to only output specific builder configurations.
|
||||
|
||||
## Limitations
|
||||
|
||||
None, really. The tool will tell you if it can't convert a part of a template,
|
||||
and whether that is a critical error or just a warning. Most of Veewee's
|
||||
functions translate perfectly over to Packer. There are still a couple missing
|
||||
features in Packer, but they're minimal.
|
||||
|
||||
## Bugs
|
||||
|
||||
If you find any bugs, please report them to the [veewee-to-packer issue
|
||||
tracker](https://github.com/mitchellh/veewee-to-packer). I haven't been able to
|
||||
exhaustively test every Veewee template, so there are certainly some edge cases
|
||||
out there.
|
||||
Loading…
Reference in new issue