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

How do you lint a role that uses custom module? #245

Closed
udondan opened this issue Feb 24, 2017 · 7 comments
Closed

How do you lint a role that uses custom module? #245

udondan opened this issue Feb 24, 2017 · 7 comments

Comments

@udondan
Copy link

udondan commented Feb 24, 2017

This is a general question, so sorry for not sticking to the given issue template. I'll create another issue with a bug report later if it makes sense.

Imagine the following scenario:

Role FOO provides a custom module foo, which can be used as

tasks:
  - name: Run foo
    foo: x=y...

Now I have a role BAR. This role has a dependency to FOO in its meta/main.yml. This works fine with ansible-galaxy. If the role has been included in a playbook the provided modules can be used in any role. In one of the tasks files of bar is a task like seen above:

tasks:
  - name: Run foo
    foo: x=y...

How would I only run the linter on the role BAR? If I do so, it complains it wasn't able find a task.

Couldn't parse task at /workspace/tasks/main.yml:3 (no action detected in task. This often indicates a misspelled module name, or incorrect module path.)
{ 'name': 'Run foo',
  'foo': { '__file__': u'/workspace/tasks/main.yml',
              '__line__': 4,
              'x': 'y'}}

I can not even disable the linting for those tasks per tags: skip_ansible_lint. I assume this is because the parsing is done by the Ansible library.

Is there a clean way to overcome this problem?

@strangeman
Copy link

willthames/ansible-review#16 here is related issue

@willthames
Copy link
Contributor

Thanks @strangeman, that's still my best solution :)

@ewascent
Copy link

Please honor the libraries setting in either the ansible.cfg file or ANSIBLE_LIBRARY environment variable

@ssbarnea
Copy link
Member

ssbarnea commented Mar 9, 2019

I think that we need an option configurable in ansible-lint config file for this, as env var ....cannot be included with the code. People should be able to run ansible-lint without alterning their environment. For the moment I define this variable in tox.ini but this does not solve the problem of running outside tox.

@ssbarnea
Copy link
Member

ssbarnea commented Jun 26, 2019

While there is a workaround mentioned at pre-commit/pre-commit#758 (comment) I am afraid that it may be usable only if your module is inside the repository itself. it will not work if that module is installed as a python package added to dependencies. I am still looking for somethign that would allow to do:

ANSIBLE_LIBRARY= {envsitepackagesdir}/zuul/ansible/base/library
ANSIBLE_ACTION_PLUGINS = {envsitepackagesdir}/zuul/ansible/base/actiongeneral

--- where {envsitepackagesdir} would be pre-commit own virtualenv.

@angelos-se
Copy link

Placing custom modules into "library" folder next to the playbook yaml file is one of the recommended way of doing this in Ansible's official document...

@ssbarnea
Copy link
Member

What is not documented is what if you have other roles or modules that are hosted inside the same repository. On open stack they spread across
multiple git repositories.

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