ansible-lint icon indicating copy to clipboard operation
ansible-lint copied to clipboard

Cannot skip load-failure false positives when using import_playbook

Open mdebord-dlr opened this issue 2 years ago • 1 comments

Summary

The linter will not skip load-failure checks for imported collection playbooks, regardless of any ignore rules added.

skip_list does not work. Nor does in-line ignores, but adding to warn_list allows the tests to at least complete.

Offending code:

- name: "Import collection playbook"
  import_playbook: my.collection.my_playbook  # noqa load-failure

or

- name: "Import collection playbook"
  import_playbook: my.collection.my_playbook
  tags:
    - "skip_ansible_lint"

or adding to global ignore in .ansible-lint

skip_list:
 - load-failure

All 3 of the above result in this failure:

load-failure: [Errno 2] No such file or directory: '<<truncated>>/my.collection.my_playbook' (filenotfounderror)
my.collection.my_playbook:1

Additional bug notes:

  • The playbook imports and executes fine during execution (even though the skip should skip even if it didn't work).
  • The collection exists and is in the appropriate collection path defined in Ansible config collections_paths (even though the skip should skip even if it was a bad path).
  • I've also tried adding to mock_modules: in .ansible-lint with no success.

Issue Type

  • Bug Report

Ansible and Ansible Lint details

>> ansible-lint --version
ansible-lint 5.4.0 using ansible 2.11.7
>> ansible --version
ansible [core 2.11.7] 
  config file = <<truncated>>/ansible.cfg
  configured module search path = ['<<truncated>>/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = <<truncated>>/.venv/lib/python3.10/site-packages/ansible
  ansible collection location = /collections
  executable location = <<truncated>>/.venv/bin/ansible
  python version = 3.10.6 (main, Aug 30 2022, 04:58:11) [Clang 13.0.0 (clang-1300.0.29.30)]
  jinja version = 3.0.3
  libyaml = True
  • ansible installation method: pip
  • ansible-lint installation method: pip

OS / ENVIRONMENT

  • MacOS 11.6
  • Python 3.10.6
  • Ansible and Ansible-lint versions noted above

STEPS TO REPRODUCE

  1. Attempt to ignore load-failure checks on import_playbook actions when importing a collection playbook.

Desired Behavior

ansible-lint should skip load-failure checks for imported collection playbooks when skipping using the documented ignore methods

Actual Behavior

ansible-lint does not skip load-failure checks for imported collection playbooks when skipping using the documented ignore methods

mdebord-dlr avatar Sep 21 '22 21:09 mdebord-dlr

I've tried the same scenario on a newer version of Ansible and Ansible-lint. My company does not yet use Ansible 2.12 yet so I'm stuck on ansible-lint v5 until the project is upgraded.

However, I tried it for troubleshooting with ansible-lint 6.6.1 using ansible 2.13.4 and the error has changed in this version, but the issue persists.

internal-error: Unexpected error code 1 from execution of: ansible-playbook --syntax-check -i localhost, playbooks/test.yaml
playbooks/test.yaml:1 ERROR! Unable to retrieve file contents
Could not find or access '<<truncated>>/playbooks/my.collection.my_playbook' on the Ansible Controller.
If you are using a module and expect the file to exist on the remote, see the remote_src option

Even with this newest version and the different error, the problem still persists. Error still throws even with ignore rule for internal-error in place, so the version update didn't seem to resolve the underlying problem.

mdebord-dlr avatar Sep 21 '22 22:09 mdebord-dlr

@mdebord-dlr I do want to fix this bug but I am having a hard time making ansible itself find playbooks inside a collection. If you can find me a collection that I can install and later execute a playbook using the documented syntax ansible-playbook namespaace.colname.playbasename -i localhost it would be awesome!

Whatever I do I still get ERROR! the playbook: a.b.c could not be found, like ansible would never even attempt to look for a play from inside a collection.

I am currently using the 2.14 beta, but I doubt that one has different behavior than last release.

ssbarnea avatar Oct 01 '22 12:10 ssbarnea

@ssbarnea Sure thing! I created an ultra-simple demo collection here: https://github.com/mdebord-dlr/basic-ansible-collection

Here is a simple demo project that utilizes the collection in the exact same way my real project does: https://github.com/mdebord-dlr/use-ansible-collection. From this project, I can successfully run ansible-playbook demo_namespace.demo_collection.foo -i localhost as you had requested (after the collection is installed of course)

mdebord-dlr avatar Oct 03 '22 18:10 mdebord-dlr

I tested with latest version 6.8.0b2 and linter validated the repository without problems. Just to be sure I modified the import_playbook name to make it invalid and run the linter again, this time it failed at syntax check:

syntax-check: Unable to retrieve file contents (syntax-check[missing-file])
playbooks/test-playbook.yml:1:1 Could not find or access '/Users/ssbarnea/c/a/3rd/use-ansible-collection/playbooks/demo_namespace.demo_collection.foo222' on the Ansible Controller.

So I am closing this as fixed. I guess it was fixed by another bugfix between these two versions.

ssbarnea avatar Oct 03 '22 20:10 ssbarnea