2

I have split my custom ansible roles and the ones downloaded from ansible-galaxy into seperate directories (./roles and ~/.ansible/roles).

In .ansible.cfg I have added the following configuration:

[...]
roles_path = ~/.ansible/roles:./roles
[...]

Ansible-lint reads my ansible.cfg and scans both directories as expected. Since I just want to lint my own ansible roles, I have added the following line to my .ansible-lint configuration:

[...]
exclude_paths:
    - ~/.ansible/roles
[...]

This unfortunately does not work, ansible-lint still scans both directories. If I expand the username explictly (e.g. - /root/.ansible/roles), ansible-lint ignores the directory correctly.

Is it somehow possible to ignore my shared roles directory without using an absolute path (since the user accounts differ between my local machine and the ci server)?

Timbo
  • 75
  • 8

1 Answers1

0

Ansible-lint will respect ANSIBLE_ROLES_PATH if you define it.

Newer versions of the linter will not report problems from files not tracked by the current repository. Almost for sure you can get around without having to add stuff to exclude_paths.

sorin
  • 161,544
  • 178
  • 535
  • 806
  • What is the meaning of "will respect" in this answer? Will it exclude the paths in ANSIBLE_ROLES_PATH from the linting or include them? Should the OP shorten their roles_path in .ansible.cfg to just include ./roles? In my experience this does not have the desired effect, the linter will still complain about third-party roles in ~/.ansible. – Ludwig Schulze Apr 24 '23 at 11:47
  • The statement "Newer versions of the linter will not report problems from files not tracked by the current repository." It may have been true when the answer was given in 2021, but it is not true now, in 2023 the linter also complains about third-party roles in ~/.ansible. – Ludwig Schulze Apr 24 '23 at 11:51