Packer ansible provisioner "ansible-playbook not found" in CI
The Packer ansible provisioner runs ansible-playbook from the runner against the build instance. If Ansible is not installed on the CI runner, the provisioner cannot start.
What this error means
packer build fails with "exec: ansible-playbook: executable file not found in $PATH" when the ansible provisioner tries to run.
packer
Error: exec: "ansible-playbook": executable file not found in $PATH
Build 'amazon-ebs.ubuntu' errored: exec: "ansible-playbook": executable file not
found in $PATHCommon causes
Ansible is not installed on the runner
The ansible provisioner runs on the CI host, not the target. A runner without Ansible cannot invoke ansible-playbook.
ansible-playbook is not on PATH
Ansible is installed under a venv or path the step does not see, so the executable is not found.
How to fix it
Install Ansible before packer build
- Add a step that installs Ansible on the runner.
- Confirm
ansible-playbook --versionworks. - Run packer build after Ansible is available.
.github/workflows/build.yml
- run: python -m pip install ansible
- run: ansible-playbook --version
- run: packer build .Point the provisioner at the right binary
If Ansible lives in a venv, set the command path so the provisioner finds it.
build.pkr.hcl
provisioner "ansible" {
playbook_file = "./playbook.yml"
command = ".venv/bin/ansible-playbook"
}How to prevent it
- Install Ansible as an explicit CI step before build.
- Verify
ansible-playbook --versionin the pipeline. - Set the provisioner
commandwhen using a venv.
Related guides
Packer shell provisioner "Script exited with non-zero exit status" in CIFix Packer "Script exited with non-zero exit status" in CI - a shell provisioner command failed on the build…
Packer file provisioner "no such file or directory" in CIFix Packer file provisioner "no such file or directory" in CI - the source path uploaded by the file provisio…
Packer "Failed to initialize" from packer init in CIFix Packer "Error: Failed to initialize" from packer init in CI - the template declares required_plugins that…