Skip to content

Latest commit

 

History

History
89 lines (71 loc) · 3.76 KB

Packer.md

File metadata and controls

89 lines (71 loc) · 3.76 KB

Packer

Interacts with Packer. The template argument must generally be a pkr.json template, pkr.hcl template, or a directory containing Packer templates and configs.

Dependencies

  • Packer CLI binary executable >= 1.7

packer.build()

Uses Packer to build an artifact from a template or template directory.

packer.build(
  bin:      '/usr/bin/packer', // optional location of packer install
  force:    false, // optional force a build to continue if artifacts exist and deletes existing artifacts
  only:     ['source.*.foo', 'source.bar.*', 'baz'], // optional builder names to build
  onError:  'default', // optional 'default' cleanup, 'abort', 'ask', or 'run-cleanup-provisioner'
  template: '/path/to/template.pkr.json', // location of packer template file or templates directory
  var:      ['foo':'bar', 'bar':'baz'], // optional variable setting
  varFile: '/path/to/variables.json' // optional location of variables file
)

packer.fmt()

Uses Packer to check for properly canonically formatted code.

packer.fmt(
  bin:      '/usr/bin/packer', // optional location of packer install
  check:    false, // optional check template and return an error if file is not formatted correctly (cannot be used with `write`)
  diff:     false, // optional present a diff if the template is not formatted correctly
  template: '/path/to/template_dir', // location of packer templates directory
  write:    true // optional write changes directly to files that are not formatted directly (cannot be used with `check`)
)

packer.init()

Uses Packer to install all the missing plugins required in a Packer template directory.

packer.init(
  bin:     '/usr/bin/packer', // optional location of packer install
  dir:     '/path/to/template_dir', // location of packer templates directory
  upgrade: false // optional update installed plugins to the latest available version within the specified constraints
)

packer.inspect(String template, String bin = '/usr/bin/packer')

Inspects a template and parses and outputs the components a template defines.

packer.inspect('/path/to/template.pkr.json', '/usr/local/bin/packer')

packer.parse(String template)

Provides a thin wrapper around HCL4j for inputting a Packer template or config, and returning a Map representing the parsed HCL2. Note this requires local installation of the HCL4j dependency, and therefore the agent must have sufficient permissions to do so.

parsedMap = packer.parse('/path/to/template.pkr.hcl')

packer.plugins()

Uses Packer to interact with plugins and display information about them.

packer.plugins(
  bin:     '/usr/bin/packer', // optional location of packer install
  command: 'installed', // one of 'installed' or 'required'
  dir:     '/path/to/template_dir', // location of directory with packer config (required for 'required' command)
)

packer.validate()

evalData and warnUndeclVar require Packer version >= 1.8.5

Uses Packer to validate a build template or template directory.

packer.validate(
  bin:           '/usr/bin/packer', // optional location of packer install
  evalData:      false, // optional evaluate datasources during validation
  only:          ['source.*.foo', 'source.bar.*', 'baz'], // optional builder names to validate
  syntaxOnly:    false, // optional only check syntax and do not verify config
  template:      '/path/to/template.pkr.hcl', // // location of packer template file or templates directory
  var:           ['foo':'bar', 'bar':'baz'], // optional variable setting
  varFile:       '/path/to/variables.json' // optional location of variables file
  warnUndeclVar: true, // optional warn on user variable files containing undeclared variables
)