I’m writing a packer file that use a galaxy collection and ansible provisioner:
provisioner "ansible" {
user = "${var.username}"
playbook_file = "${var.home}/.ansible/collections/ansible_collections/devops/playbooks/basic.yml"
extra_arguments = [
"--extra-vars", "install_docker=true", "-vvvv", "--scp-extra-args", "'-O'"
]
ansible_ssh_extra_args = [
"-oHostKeyAlgorithms=+ssh-rsa -oPubkeyAcceptedKeyTypes=+ssh-rsa"
]
galaxy_file = "collection-requirements.yml"
}
The execution fails with the following error:
Error: Failed preparing provisioner-block "ansible" ""
on main.pkr.hcl line 29:
(source code not available)
1 error(s) occurred:
* playbook_file:
/home/me/.ansible/collections/ansible_collections/devops/playbooks/openvpn.yml
is invalid: stat
/home/me/.ansible/collections/ansible_collections/devops/playbooks/openvpn.yml:
no such file or directory
Packer wants to check if the file exists, but those playbook files are not meant to be there until packer will pull the galaxy ansible collection. Interestingly, if I just create the folder structure, and touch an empty openvpn.yml file, validate will work, packer starts, pulls all the collection correctly overwriting the empty file, and runs the playbook remotely as expected.
Is there any way to avoid such check? Ansible provisioner and galaxy support is especially convenient in order to avoid a manual galaxy collection prior the packer execution, which is actually performed later by packer itself. Why so packer is looking for a file that are later downloaded by packer itself? That is actually forcing me to pre-install the collection, defeating the purpose of the galaxy_file support. I’m wondering if is a bug or my misunderstanding of the ansible provisioner. Can you please advise?