community.general.packer module – Manage HashiCorp Packer builds
Note
This module is part of the community.general collection (version 14.0.0).
You might already have this collection installed if you are using the ansible package.
It is not included in ansible-core.
To check whether it is installed, run ansible-galaxy collection list.
To install it, use: ansible-galaxy collection install community.general.
You need further requirements to be able to use this module,
see Requirements for details.
To use it in a playbook, specify: community.general.packer.
New in community.general 13.5.0
Synopsis
Manage Packer builds and templates.
Supports building and initializing Packer templates.
Requirements
The below requirements are needed on the host that executes this module.
packer >= 1.7.0
Parameters
Parameter |
Comments |
|---|---|
Clean up temporary files after build ( Choices:
|
|
Enable colored output if Choices:
|
|
Build all builders except the specified ones ( |
|
Force rebuilding (passes Choices:
|
|
Set the log level ( Choices:
|
|
Generate the output in machine-readable format ( Choices:
|
|
Name of the Packer build configuration (for identification). |
|
Build only the specified builders ( |
|
Disable parallel building ( Choices:
|
|
Desired state of the Packer build configuration. Choices:
|
|
Path to the Packer template file or directory. Required for all states. |
|
List of variable files to load ( Default: |
|
Dictionary of variables to pass to Packer ( Default: |
Attributes
Attribute |
Support |
Description |
|---|---|---|
Support: partial In check mode, Check mode is ignored for
|
Can run in |
|
Support: none |
Returns details on what has changed (or possibly needs changing in |
Examples
- name: Initialize Packer template (install plugins)
community.general.packer:
name: init-template
state: initialized
template: aws-ubuntu.pkr.hcl
- name: Initialize Packer template from directory
community.general.packer:
name: init-template-dir
state: initialized
template: ./packer-templates/
- name: Build AWS AMI with Packer (or validate in check_mode)
community.general.packer:
name: my-ami
state: built
template: aws-ubuntu.pkr.hcl
variables:
aws_region: us-west-2
instance_type: t2.micro
force: false
- name: Build from directory containing multiple templates
community.general.packer:
name: multi-template-build
state: built
template: ./packer-templates/
force: false
- name: Validate template using check_mode
community.general.packer:
name: validate-check
state: built
template: template.pkr.hcl
var_files:
- dev.pkrvars.hcl
- common.pkrvars.hcl
check_mode: true
- name: Build with force rebuild
community.general.packer:
name: force-build
state: built
template: template.pkr.hcl
force: true
parallel: false
machine_readable: true
- name: Build only specific builders
community.general.packer:
name: selective-build
state: built
template: template.pkr.hcl
only:
- amazon-ebs.builder1
- virtualbox-iso.builder2
- name: Build local artifact (VirtualBox)
community.general.packer:
name: local-build
state: built
template: virtualbox.pkr.hcl
force: true
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
|---|---|
List of created artifacts. Returned: when Sample: |
|
Full command line executed as a list. Returned: always Sample: |
|
Packer version used. Returned: always Sample: |