Add cleanup step for empty mocked role folders #2235
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before
If we want to test one role based on another role, we can define the role name in
molecule/[scenario-name]/requirements.yml
and add it in mock_roles in.ansible-lint
config file.Assume the dependency role is
zhan9san.test
One the role is defined in mock_roles in
.ansible-lint
file,ansible-lint
would create an empty dir under~/.cache/ansible-compat/9eeb38/roles/zhan9san.test
.molecule dependency
does install the role defined inmolecule/[scenario-name]/requirements.yml
but under~/.cache/molecule/ansible-role-test-lint/default/roles
dir.When we run
molecule test
, it will set ANSIBLE_ROLES_PATH=$runtime_cache_dir/roles:$ephemeral_directory/roles/:$project_directory/../:~/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
referring to ANSIBLE_ROLES_PATH.The first path
$runtime_cache_dir/roles
inANSIBLE_ROLES_PATH
is~/.cache/ansible-compat/0ad53a/roles
while the second$ephemeral_directory/roles/
is~/.cache/molecule/ansible_role_example/default/roles
.As we know, the order of
ANSIBLE_ROLES_PATH
matters, andzhan9san.test
does exist in first role path, soansible
will run it without error if it is an empty role.After
Once the empty role dirs are deleted, ansible will choose the role under
~/.cache/molecule/ansible-role-test-lint/default/roles
dir.Reference: ansible/molecule#3610 (comment)
Fixes: #2234