Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cleanup step for empty mocked role folders #2235

Merged
merged 2 commits into from Jul 12, 2022

Conversation

zhan9san
Copy link
Contributor

@zhan9san zhan9san commented Jul 12, 2022

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 in molecule/[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 in ANSIBLE_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, and zhan9san.test does exist in first role path, so ansible 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

@zhan9san zhan9san requested review from a team as code owners July 12, 2022 10:40
@ssbarnea ssbarnea added the bug label Jul 12, 2022
@ssbarnea ssbarnea changed the title remove empty mocked role dirs Add cleanup step for empty mocked role dirs Jul 12, 2022
@ssbarnea ssbarnea changed the title Add cleanup step for empty mocked role dirs Add cleanup step for empty mocked role folders Jul 12, 2022
@ssbarnea ssbarnea merged commit 3aa0b27 into ansible:main Jul 12, 2022
@zhan9san zhan9san deleted the feature/remove-empty-mocked-role-dirs branch July 13, 2022 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Empty mocked role dir makes ansible role messed up
2 participants