Open Tcharl opened 1 year ago
@Tcharl
Thanks for reporting this issue.
If I understand it correctly, the X-problem is to share the dependency and the Y-problem is to support ANSIBLE_ROLES_PATH environment variable.
I'll take a look at this issue.
Is this maybe related to my problem that Ansible / Molecule is failing to find the role in the project directory?
Error log:
ERROR! the role 'trallnag.awscli' was not found in /home/runner/work/ansible-role-awscli/ansible-role-awscli/molecule/default/roles:/home/runner/.cache/ansible-compat/52a4ae/roles:/home/runner/.cache/molecule/ansible-role-awscli/default/roles:/home/runner/work/ansible-role-awscli:/home/runner/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/runner/work/ansible-role-awscli/ansible-role-awscli/molecule/default
The error appears to be in '/home/runner/work/ansible-role-awscli/ansible-role-awscli/molecule/default/converge.yml': line 15, column 15, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
ansible.builtin.include_role:
name: trallnag.awscli
^ here
It is the same locally. It only works when I install the role locally into ~/.cache/ansible-compat/52a4ae/roles
. But shouldn't it detect the project role automatically?
I tried setting
provisioner:
name: ansible
ANSIBLE_ROLES_PATH: "../../"
But this did not help.
ansible~=7.4
molecule~=5.0
molecule-plugins[docker]~=23.4
docker~=6.0
Maybe related: https://github.com/ansible-community/molecule/issues/3806
I ended up using these variable as a prefix of the command (and ensure that it's systematic through tox) and creating two different requirements.yml files: local
and standalone
so that I don't import my local roles in cache.
Not optimal but works :-).
Will publish a sample repo soon (while I'll get something acceptable to be public)
What I don't understand why it works for some people / repositories without specification of ANSIBLE_ROLES_PATH
anywhere. For example here: https://github.com/geerlingguy/ansible-role-apache
I found it out. Molecule does not consider .yaml
. It only looks for .yml
.
@Tcharl
Now the collections and roles would all be installed in the default directory(~/.ansible/collections and ~/.ansible/roles), which is shipped via isolated=False
You don't need to define ANSIBLE_COLLECTIONS_PATH
and ANSIBLE_ROLES_PATH
explicitly.
Could you verify whether it works?
Hi @zhan9san , and thanks for your help, I whish I knew python and its ecosystem better ^^
It doesn't answer to the use case, see for example https://github.com/OsgiliathEnterprise/servicemesh.
I typically rely on roles only (I do not use collection at all, overkill/not really fitting with the use case).
I try to make all my roles atomic as possible: example role_nginx
, role_virtualhost
.
And I usually use a 'monorepo' approach locally:
workspace_root
|_role_nginx
|_role_virtualhost
When I code the higher-level role (the role_virtualhost
here), I usually also adapt the roles in dependency to enhance it.
I also want speed while doing it, so want to avoid releasing my modifications on the child role to galaxy (role_nginx
) to test my parent role (role_virtualhost
) with molecule, taking into account the modifications made on the child (that aren't released, neither gitted yet). I also don't want to test my child role with molecule (sometimes it's not worth to molecule everything).
I used to play with these variables in the molecule.yml file to let it work this way, and now forced to use another framework (tox) to inject these variable at execution
@Tcharl
Please allow me to recap your idea. You hope molecule can support the local roles as dependencies instead of installing them from remote galaxy. This does make sense.
Have you had a workaround? Do you still need it fixing?
Issue Type
`molecule converged not take environment variables into account.
previously
Was working accordingly (in a mono repo environments, updates were taken 'live').
Which is no more the situation with 4.0.4.
Molecule and Ansible details
Molecule installation method (one of):
Ansible installation method (one of):
Detail any linters or test runners used:
Desired Behavior
Using
Let roles that are located in the same parent folder to be resolved instead of the remote dependency, which is useful when implementing a big chain of dependent roles (avoid tagging the dependency, ansible-galaxy referencing, ...).
Is it possible to get the same behavior (another way), or to support the feature again?
Actual Behavior