Setting hosts: all
is fine if the playbook is used exclusively for your Packer build.
If you're re-using a playbook that also needs to run against hosts specified in an inventory file, for example:
[web_servers]
web1.example.com
web2.example.com
[db_servers]
db.example.com
...then you can add the inventory_groups
attribute to your ansible-local
provisioner, and Packer will assign localhost to those group(s):
"provisioners": [
{ "type": "file", "source": "my_folder", "destination": "/tmp/" },
{ "type": "shell", "script": "provisioner.sh" },
{
"type": "ansible-local",
"staging_directory": "/tmp/my_folder",
"playbook_file": "my_folder/playbook.yml",
"inventory_groups": "web_servers"
}
]
For more details, see the Optional sub-section of the Packer doc for ansible-local provisioner Configuration Reference