Unable to use ansible-local provisioner with packer in AWS codebuild pipeline

Hello. I am new to how Packer works, read the documentation but it did not really help me with this. I am trying to better understand how I can tie in Ansible-local or ansible-remote as part of a provisioning step in building images with packer.

What is the best approach to doing that?

I want to try and “bake-in” as much as I can to the image before rolling it out.

attached are my JSON & playbook file examples

Any advice would be greatly appreciated. Thank you.

Put the ansible source in a subdir (including roles etc.) to avoid uploading packer_cache to your image.

–extra-vars can take a value from environment variables.

      "extra_arguments": [
        "--extra-vars \"image={{user `image`}}\""
      "playbook_dir": "./ansible",
      "playbook_file": "ansible/packer.yml",
      "type": "ansible-local"
    "variables": {
      "image": "{{env `IMAGE`}}"