Ansible collections should be installed before validation of packer build file. Build will fail.
This issue was originally opened by @queglay as hashicorp/packer#11058. It was migrated here as a result of the Packer plugin split. The original body of the issue is below.
Overview of the Issue
If playbooks are attempted to be run from within a collection, packer will error since it has not yet installed the requirements.
Reproduction Steps
Try to run a playbook from within a collection.
Packer version
v1.7.2
Simplified Packer Buildfile
example:
provisioner "ansible" {
playbook_file = "./ansible/collections/ansible_collections/firehawkvfx/fsx/fsx_packages.yaml"
extra_arguments = [
"-vv",
"--extra-vars",
"variable_user=deadlineuser resourcetier=${var.resourcetier} variable_host=default user_deadlineuser_pw='' package_python_interpreter=/usr/bin/python2.7"
]
collections_path = "./ansible/collections"
roles_path = "./ansible/roles"
ansible_env_vars = ["ANSIBLE_CONFIG=ansible/ansible.cfg"]
galaxy_file = "./requirements.yml"
only = [
"amazon-ebs.centos7-rendernode-ami",
]
}
Operating system and Environment details
Amazon linux 2
Log Fragments and crash.log files
Error: Failed preparing provisioner-block "ansible" ""
on /home/ec2-user/environment/firehawk/deploy/packer-firehawk-amis/modules/firehawk-ami/firehawk-ami.pkr.hcl line 814:
(source code not available)
1 error(s) occurred:
* playbook_file:
./ansible/collections/ansible_collections/firehawkvfx/fsx/fsx_packages.yaml is
invalid: stat
./ansible/collections/ansible_collections/firehawkvfx/fsx/fsx_packages.yaml: no
such file or directory
Copying Moss's comment from the originating issue:
I'm not an ansible expert but our provisioner expects an existent playbook file to run ansible. As the ansible config you provided is creating the collection, you can change this one to use an existent playbook and then use a second ansible provisioner that will finally use the created collection playbook. Does that work?
Cheers for the suggestion, I will test this on the next build soon.
I follow this pattern (create shim playbook that just uses a play from a collection).
It isn't great, but works alright.
Would be cool if we could do as https://github.com/hashicorp/packer-plugin-ansible/issues/82 suggests and use the dotted name to reference the play inside the collection.