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

Modules in roles included via 'import_role' are not detected #644

Closed
drybjed opened this issue Dec 8, 2019 · 5 comments
Closed

Modules in roles included via 'import_role' are not detected #644

drybjed opened this issue Dec 8, 2019 · 5 comments

Comments

@drybjed
Copy link
Contributor

drybjed commented Dec 8, 2019

Issue Type

  • Bug report

Ansible and Ansible Lint details

ansible 2.9.1
  config file = None
  configured module search path = ['/home/drybjed/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/drybjed/.local/lib/python3.7/site-packages/ansible
  executable location = /home/drybjed/.local/bin/ansible
  python version = 3.7.3 (default, Apr  3 2019, 05:39:12) [GCC 8.3.0]

ansible-lint 4.2.0
  • ansible installation method: pip
  • ansible-lint installation method: pip

Desired Behaviour

I have a set of roles where one role (ansible_plugins) contains custom Ansible modules. Other roles that use these modules, include the ansible_plugins role using the import_role module, and role works fine, similarly to how the role with custom modules could be included via dependencies list in meta/main.yml file.

Actual Behaviour (Bug report only)

Currently using import_role instead of putting the role in dependencies results in ansible-lint not being able to detect the custom Ansible modules. This can be verified by running commands on a host with ansible-lint installed:

git clone https://github.com/debops/debops /tmp/debops && cd /tmp/debops
ansible-lint ansible/playbooks/service/cron.yml

The debops.cron role uses a custom dpkg_divert Ansible module which is included in the debops.ansible_plugins role. When the above command is executed, the result is:

Couldn't parse task at /tmp/debops/roles/debops.cron/tasks/main.yml:35 (couldn't resolve module/action 'dpkg_divert'. This often indicates a misspelling, missing collection, or incorrect module path.

The error appears to be in '<unicode string>': line 35, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

(could not open file to display line))
{ 'dpkg_divert': { '__file__': '/home/drybjed/debops/roles/debops.cron/tasks/main.yml',
                   '__line__': 36,
                   'delete': True,
                   'path': '/etc/crontab',
                   'state': '{{ cron__crontab_deploy_state }}'},
  'name': 'Divert the original crontab configuration',
  'skipped_rules': [],
  'tags': ['role::cron:crontab'],
  'when': "cron__enabled|bool and ansible_pkg_mgr == 'apt'"}

This setup works fine in Ansible itself.

@nqb
Copy link

nqb commented Jan 9, 2020

Hello,

Any update on this issue ?

drybjed added a commit to drybjed/debops that referenced this issue Jan 9, 2020
Ansible Galaxy does not support role dependencies in Ansible
Collections. According to ansible/galaxy#1938
instead of using role dependencies, the 'import_role' has to be used in
this case.

The ansible-lint script at the moment does not correctly detect custom
Ansible modules in roles imported using the 'import_role' Ansible module
(ansible/ansible-lint#644) and exits with an
error in such case.

To reconcile this issue, all of the role dependencies from DebOps roles
have been dropped and they are imported via the 'import_role' module. To
avoid broken tests, the 'ansible-lint' test in the DebOps test suite has
been disabled for now.
@fooka03
Copy link

fooka03 commented Mar 6, 2020

As a workaround you could set ANSIBLE_LIBRARY to include the path to the imported role for the ansible-lint execution. We use this with our molecule linting:

lint: |
  set -e
  yamllint .
  ANSIBLE_LIBRARY=${MOLECULE_EPHEMERAL_DIRECTORY}/roles/<custom imported role>/library/:${MOLECULE_EPHEMERAL_DIRECTORY}/roles/<another custom imported role>/library/:${MOLECULE_EPHEMERAL_DIRECTORY}/library/:${MOLECULE_PROJECT_DIRECTORY}/library/ ansible-lint
  flake8

@geerlingguy
Copy link

I seem to be getting this when I use a module from a collection that is called from a module using its shortname if the module has the collection defined in the collections keyword inside the role's meta/main.yml. Works fine in the playbook but kills ansible-lint:

$ ansible-lint
Couldn't parse task at /Users/jgeerling/Development/GitHub/turing-pi-cluster/roles/minecraft/tasks/main.yml:9 (couldn't resolve module/action 'helm_repository'. This often indicates a misspelling, missing collection, or incorrect module path.

The error appears to be in '<unicode string>': line 9, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

(could not open file to display line))
{ 'helm_repository': { '__file__': '/Users/jgeerling/Development/GitHub/turing-pi-cluster/roles/minecraft/tasks/main.yml',
                       '__line__': 11,
                       'name': 'stable',
                       'repo_url': 'https://kubernetes-charts.storage.googleapis.com'},
  'name': 'Add stable chart repo.',
  'skipped_rules': []}

@miettal
Copy link

miettal commented May 30, 2020

I seem to be getting this when I use a module from a collection that is called from a module using its shortname if the module has the collection defined in the collections keyword inside the role's meta/main.yml. Works fine in the playbook but kills ansible-lint:

I have the same issue.

// And ansible-lint doesn't seem to load "collection_path".

berendt pushed a commit to osism/ansible-collection-commons that referenced this issue Aug 18, 2020
ansible/ansible-lint#644

Signed-off-by: Christian Berendt <berendt@betacloud-solutions.de>
berendt pushed a commit to osism/ansible-collection-commons that referenced this issue Aug 18, 2020
ansible/ansible-lint#644

Signed-off-by: Christian Berendt <berendt@betacloud-solutions.de>
berendt pushed a commit to osism/ansible-collection-commons that referenced this issue Aug 18, 2020
ansible/ansible-lint#644

Signed-off-by: Christian Berendt <berendt@betacloud-solutions.de>
@ssbarnea
Copy link
Member

Current error no longer reproduces with code from master branch, running ansible-lint ansible/playbooks/service/cron.yml returns success.

killermoehre pushed a commit to killermoehre/ansible-collection-commons that referenced this issue Jan 29, 2024
ansible/ansible-lint#644

Signed-off-by: Christian Berendt <berendt@betacloud-solutions.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants