neillturner / kitchen-ansible

Ansible Provisioner for Test Kitchen
Other
350 stars 134 forks source link

Can't find role when using roles_path option in kitchen.yml #320

Open TatevyanA opened 4 years ago

TatevyanA commented 4 years ago

In kitchen.yml I have these two options:

root_path: /tmp/kitchen/ansible
roles_path: <%= ENV\['WORKSPACE'\] %>/ansible-roles

where WORKSPACE env var is set to my working dir, which contains subdir named 'ansible-roles' with all my roles.

After running kitchen converge I get an error: ERROR! the role 'some_role' was not found in /tmp/kitchen/ansible/roles:/tmp/kitchen/ansible/roles:/tmp/kitchen/ansible/

When I login to the vm, I can find my role(s) (e.g. 'some_role') under { root_path }/roles/ansible-roles/. So, basically, kitchen transfers my roles to the vm, but it doesn't append the ANSIBLE_ROLES_PATH var with { root_path }/roles/ansible-roles/, thus the latter fails to find the listed role(s) in default.yml.

However, if I rename my local directory from 'ansible-roles' to just 'roles' and set the 'roles_path' to '<%= ENV['WORKSPACE'] %>/roles' accordingly, as described exactly in Tips, then the kitchen copies the contents of local 'roles' dir directly to { root_path }/roles/, hence ansible finds the listed 'some_role' and starts playbook successfully.

Now, if instead use additional_copy_role_path, then the ANSIBLE_ROLES_PATH is always appended with correct path, and it works whichever my local dir is named.

Question: is this intended behavior? Are the Tips describing correct case of using roles' path templating , and it should always point to /roles explicitly to otherwise it will fail? Could you please elaborate on when exactly to use the the 'roles_path' option, and if it refers to local or remote (on vm) path to roles?

TatevyanA commented 4 years ago

This line looks weird to me. So, unless roles_path is null, it appends the 'roles_paths' with one more '{ root_path }/roles' https://github.com/neillturner/kitchen-ansible/blob/fa49caef12a85fb60f78cb266c7641cad2a64fe3/lib/kitchen/provisioner/ansible_playbook.rb#L974

As a result, from the error above, we can see the duplicate location: /tmp/kitchen/ansible/roles:/tmp/kitchen/ansible/roles

Could you confirm, this is correct?

neillturner commented 4 years ago

the whole role_path implementation is quite complex and its been awhile since i looked at it. it could well be a bug. Its very hard to handle all possible cases. the code is fairly stable now and while not perfect you can get testing done with it.
if you run with kitchen debugging set to maximum then you get some indication what it is doing.