ยปOnly and Except

only and except are keywords used to filter what runs in your Packer build, they can be seen as a command line argument:

  • -except=foo,bar,baz - Run all the builds and post-processors except those with the given comma-separated names. In legacy JSON templates, build names default to the types of their builders (e.g. docker or amazon-ebs or virtualbox-iso, unless a specific name attribute is specified within the configuration. In HCL2 templates, the "name" is the source block's "name" label, unless an in-build source definition adds the "name" configuration option. Any post-processor following a skipped post-processor will not run. Because post-processors can be nested in arrays a different post-processor chain can still run. A post-processor with an empty name will be ignored.
  • -only=foo,bar,baz - Only run the builds with the given comma-separated names. In legacy JSON templates, build names default to the types of their builders (e.g. docker or amazon-ebs or virtualbox-iso, unless a specific name attribute is specified within the configuration. In HCL2 templates, the "name" is the source block's "name" label, unless an in-build source definition adds the "name" configuration option.

They can also be seen in a template to run or skip provisioners and/or post-processors for a specific source:

Note that cli arguments can be used with a glob operator, using the previous configuration:

  • packer build -only 'my_build.*' dir: will only run the builds in blocks named my_build.

  • packer build -only '*.amazon-ebs.*' dir: will only run the builds with a source of type amazon-ebs.

  • packer build -only '*.second-example-local-name' dir: will only run that specifically named build.

Note: In the cli only and except will match agains build names (for example:my_build.amazon-ebs.first-example) but in a provisioner they will match on the source name (for example:amazon-ebs.third-example).