Parameter roles_path is not taken into account with ansible provisioner on azure-arm
Gist related content (forgive me, I don't know how to quote it yet)
https://gist.github.com/nWmCZ/70441b91ee64f3cef0fc14b1e8ec09b5
EDIT:
Already found workaround:
"ansible_env_vars": [ ["ANSIBLE_ROLES_PATH=/git/roles"] ]
This is also present in amazon-ebs
Packer version 1.4.5
It looks like roles_path
is used only by ansible-galaxy
❯ packer version
Packer v1.5.6
❯ cat packer.json
...
"provisioners": [
{
"type": "ansible",
"only": ["googlecompute"],
"playbook_file": "../ansible/playbooks/core.yml",
"roles_path": "../ansible/roles",
"groups": ["core", "engine"],
"user": "packer",
"extra_arguments": ["--become"],
"keep_inventory_file": true
},
...
❯ ls -l1 ../ansible/roles
cloudalchemy.node-exporter
os
engine
zabbix-agent
❯ packer build -only googlecompute packer.json
googlecompute: output will be in this color.
==> googlecompute: Checking image does not exist...
==> googlecompute: Creating temporary SSH key for instance...
==> googlecompute: Using image: centos-7-v20200603
==> googlecompute: Creating instance...
googlecompute: Loading zone: europe-west1-b
googlecompute: Loading machine type: n1-standard-1
googlecompute: Requesting instance creation...
googlecompute: Waiting for creation operation to complete...
googlecompute: Instance has been created!
==> googlecompute: Waiting for the instance to become running...
googlecompute: IP: 34.76.178.206
==> googlecompute: Using ssh communicator to connect: 34.76.178.206
==> googlecompute: Waiting for SSH to become available...
==> googlecompute: Connected to SSH!
==> googlecompute: Provisioning with Ansible...
googlecompute: Setting up proxy adapter for Ansible....
==> googlecompute: Executing Ansible: ansible-playbook -e packer_build_name=googlecompute -e packer_builder_type=googlecompute -e ansible_ssh_private_key_file=/var/folders/sj/t6k0scl12f786k43wjyn5lsm0000gn/T/ansible-key144865815 --ssh-extra-args -o IdentitiesOnly=yes -i /var/folders/sj/t6k0scl12f786k43wjyn5lsm0000gn/T/packer-provisioner-ansible435717770 /Users/bborysenko/src/iac/ansible/playbooks/bi-core.yml --become
googlecompute: ERROR! the role 'os' was not found in /Users/bborysenko/src/iac/ansible/playbooks/roles:/Users/bborysenko/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/Users/bborysenko/src/iac/ansible/playbooks
googlecompute:
googlecompute: The error appears to be in '/Users/bborysenko/src/iac/ansible/playbooks/bi-core.yml': line 5, column 5, but may
googlecompute: be elsewhere in the file depending on the exact syntax problem.
googlecompute:
googlecompute: The offending line appears to be:
googlecompute:
googlecompute: roles:
googlecompute: - role: os
googlecompute: ^ here
==> googlecompute: Provisioning step had errors: Running the cleanup provisioner, if present...
==> googlecompute: Deleting instance...
googlecompute: Instance has been deleted!
==> googlecompute: Deleting disk...
googlecompute: Disk has been deleted!
The same on VirtualBox-ovf. Any workaround?
I have something like this:
{
"type": "ansible",
"ansible_env_vars": [
"ANSIBLE_ROLES_PATH={{user `ansible_roles_path` }}",
"ANSIBLE_HOST_KEY_CHECKING=False",
"ANSIBLE_SSH_ARGS='-o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'"
],
"extra_arguments": [
"--extra-vars", "@variables.yml",
"--extra-vars", "ansible_host={{user `ansible_host`}} ansible_connection={{user `ansible_connection`}}"
],
"user": "root",
"playbook_file": "./provision.yml"
}
And run the build with:
packer build \
-var 'ansible_roles_path=/Users/zentavr/Development/dockerfiles/_ansible-roles' \
-var 'project_path=/Users/zentavr/Development/dockerfiles/ejbca' \
packer.json
My packer is not the latest version though.
@zentavr thank you for the hint!
I've created ansible.cfg in the *.pkr.hcl's file directory and it works:
[defaults]
roles_path = path/to/ansible/roles
@zentavr thank you for the hint!
I've created ansible.cfg in the *.pkr.hcl's file directory and it works:
[defaults] roles_path = path/to/ansible/roles
I see. I moved that to the parameters, because the code is shareable between the developers and Jenkins build nodes.
Question for a maintainer - do we want to override (probably merge) the ANSIBLE_ROLES_PATH
if the roles_path
parameter is provided, or should people configure their ansible.cfg
or set their ansible_env_vars
themselves?
If you want to semi-intelligently merge the provided env var with the roles_path
/collections_path
I can take a crack at that PR.
Good question. I'd merge a PR that adds ANSIBLE_ROLES_PATH if roles path is set, but I would ideally not want to override any user-set instances of ANSIBLE_ROLES_PATH.