Hi. i'm have such structure of my projects directory
/home/shirokih % tree -L 2 -d projects
projects
βββ ansible
βΒ Β βββ ansible-role-alerta-notifications
....
βββ ansible_deploy
βΒ Β βββ library
βΒ Β βββ lookup_plugins
βΒ Β βββ molecule < ---------------- here is molecule dir
βΒ Β βΒ Β βββ default
βΒ Β βΒ Β βββ single
βΒ Β βββ noc_roles
βΒ Β βΒ Β βββ noc
βΒ Β βΒ Β βββ web
βΒ Β βββ system_roles
βΒ Β βΒ Β βββ clickhouse
βΒ Β βΒ Β βββ grafana
βΒ Β βΒ Β βββ mongod
βΒ Β βΒ Β βββ postgres
...
βββ clickhouse
....
βββ external
βΒ Β βββ ...
βββ infrastructure
βΒ Β βββ ....
βββ noc
βΒ Β βββ ....
βββ postgres
....
and the following molecule.yml
...
provisioner:
name: ansible
env:
ANSIBLE_ROLES_PATH: /home/shirokih/projects/ansible_deploy/additional_roles:/home/shirokih/projects/ansible_deploy/system_roles:/home/shirokih/projects/ansible_deploy/noc_roles
TOWER_SHOW_SECRETS: "True"
ANSIBLE_STDOUT_CALLBACK: debug
ANSIBLE_CALLBACK_WHITELIST: timer,profile_tasks
ANSIBLE_LOAD_CALLBACK_PLUGINS: "True"
config_options:
defaults:
roles_path: ????
...
with default molecule roles_path i got
ERROR! the role 'pre' was not found in /home/shirokih/projects/ansible_deploy/molecule/default/roles:/tmp/molecule/ansible_deploy/default/roles:/home/shirokih/projects:/home/shirokih/projects/ansible_deploy/molecule/default
after adding ANSIBLE_ROLES_PATH i got additional path. and it seems that playbook launches
but it fails on postgres role.
it is in /home/shirokih/projects/ansible_deploy/system_roles and i have directory with same name in projects dir.
same with each directory listed in the beginning.
How can i overwrite roles_path to save regular project directory ?
it seems that restricting editing of default roles path is kind of security feature.
Can i add some key like s_in_iot_stands_for_security: True and pretty big red label instead of patching ?
oh btw:
% ansible-config dump |grep ROLES_PATH
DEFAULT_ROLES_PATH(default) = [u'/home/shirokih/.ansible/roles', u'/usr/share/ansible/roles', u'/etc/ansible/roles']
How can i overwrite roles_path to save regular project directory ?
You already answered your own question. You change it by setting ANSIBLE_ROLES_PATH. You're running molecule in a non-standard way, so you're going to run into odd configuration changes required to make it work. Molecule is intended to live inside the role it is testing.
after adding ANSIBLE_ROLES_PATH i got additional path. and it seems that playbook launches
but it fails on postgres role.
I can't tell you why it failed, b/c this bug makes no mention of why.
Molecule is intended to live inside the role it is testing.
thats ok.
but what for ../../../ is added as roles path ?
I can't tell you why it failed, b/c this bug makes no mention of why.
ok. The only one way to show witch current roles path is i found is to drop an error with not found role
here it is.
ERROR! the role 'pre2' was not found in
/home/shirokih/projects/ansible_deploy/molecule/default/roles
:/tmp/molecule/ansible_deploy/default/roles
:/home/shirokih/projects
:/home/shirokih/projects/ansible_deploy/molecule/default
that is role_path set by molecule.
than setting ANSIBLE_ROLES_PATH i've got
ERROR! the role 'pre2' was not found in
/home/shirokih/projects/ansible_deploy/molecule/default/roles
:/tmp/molecule/ansible_deploy/default/roles
:/home/shirokih/projects
:/home/shirokih/projects/ansible_deploy/additional_roles
:/home/shirokih/projects/ansible_deploy/system_roles
:/home/shirokih/projects/ansible_deploy/noc_roles
:/home/shirokih/projects/ansible_deploy/molecule/default
Path was not replaced but append only. Search path is looked from /home/shirokih/projects/ansible_deploy/molecule/default/roles to /home/shirokih/projects/ansible_deploy/molecule/default with first fond condition.
For role postres first found condition is located in /home/shirokih/projects/postgres but not in /home/shirokih/projects/ansible_deploy/system_roles
But /home/shirokih/projects/postgres is not a role but a postgres sources. so ansible can't find any tasks or anything there. so it just moves forward. it results that postgres role is just skipped.
ANSIBLE_ROLES_PATH is append to a default internal path Molecule sets. Run molecule --debug converge and you can see what Molecule is setting.
How can i modify internal set ?
ok. it seems there was some kind of war to make it right. previously roles_path was 59678f34c35cba8950dbd6ebfaeed2de641f01f3
than after refactoring it become 2b864ebff1893f10a996c02092e344994d8215c3
like after all os.cwd + .. so it seems that line is my problem.
So that behavior looks reasonable for role testing but breaks things in my setup.
setting default role_path via config file is restricted.
setting ANSIBLE_ROLES_PATH have no optout options.
pretty complicated. i can't see any simple backward compatible option to fix that
removing
https://github.com/metacloud/molecule/blob/e9f3e33fb6b0a2b7dd2b7e5f6310e38a35fd7ab7/molecule/provisioner/ansible.py#L321-L323
fixes my setup.
Run on this problem too. Why can't we be allowed to modify that path?.. The main problem is that molecule add it's paths before the ansible ones.
Ran into this same issue. I need Molecule to not check adjacent paths directories for roles, which in the environment I'm working _have nothing to do with molecule_.
I understand the internal default but find that you can't modify it to be arbitrary and poor.
@zolvaring and @Oloremo: I can see what you mean. This is a closed ticket though. Perhaps create a new one where @ssbarnea and others are more likely to see it?
I do see comments but if you create a new ticket, please be sure you explain the issue well. So far I was not able to understand the exact issue. Maybe real world example where it fails?
Molecule is primary aimed to test βstandardβ ansible repositories with minimal effort. Anything diverging from recommended layouts is likely to cause problems. I would even be inclined to refuse adding more complexity in order to support some non-standard setups.
@ssbarnea the first message it pretty descriptive and real world.
Most helpful comment
Run on this problem too. Why can't we be allowed to modify that path?.. The main problem is that molecule add it's paths before the ansible ones.