Skip to content

exception from ArgsRule.matchtasks (playbook): attempted relative import with no known parent package #4270

Open
@CAAHS

Description

@CAAHS
Summary

Running ansible-lint(1) emits a diagnostic message:

WARNING Ignored exception from ArgsRule.matchtasks while processing plays/fact-cache.yml (playbook): attempted relative import with no known parent package

Issue Type
  • Bug Report
OS / ENVIRONMENT
$ ansible-lint --version
ansible-lint 24.7.0 using ansible-core:2.17.2 ansible-compat:24.7.0 ruamel-yaml:0.18.6 ruamel-yaml-clib:0.2.8
  • ansible installation method: pip
  • ansible-lint installation method: pip (same)
STEPS TO REPRODUCE

We use the ansible-lint version as documented and the following plays/fact-cache.yml (playbook):

#!/usr/bin/env ansible-playbook
---

- name: 'Refresh Fact Cache'
  hosts: all
  tasks:
    - name: Refresh all machine facts from the cache
      setup:
        gather_subset: all
        gather_timeout: 10
Desired Behavior

The above documented diagnostics are not emitted.

Actual Behavior

The above documented diagnostics are emitted.

Excerpt from extra verbosity:

$ ansible-lint fixtures plays roles -vvvv
...
DEBUG    Running rule args
WARNING  Ignored exception from ArgsRule.matchtasks while processing plays/fact-cache.yml (playbook): attempted relative import with no known parent package
DEBUG    Ignored exception details
Traceback (most recent call last):
  File "/.../python-3.10/lib/python3.10/site-packages/ansiblelint/_internal/rules.py", line 94, in getmatches
    matches.extend(method(file))
  File "/.../python-3.10/lib/python3.10/site-packages/ansiblelint/rules/__init__.py", line 178, in matchtasks
    result = self.matchtask(task, file=file)
  File "/.../python-3.10/lib/python3.10/site-packages/ansiblelint/rules/args.py", line 161, in matchtask
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/.../python-3.10/lib/python3.10/site-packages/ansible/modules/setup.py", line 174, in <module>
    from ..module_utils.basic import AnsibleModule
ImportError: attempted relative import with no known parent package
...

As we're getting a stack trace, also the output of the Ansible playbook syntax check command:

$ ansible-playbook --syntax-check plays/fact-cache.yml

playbook: plays/fact-cache.yml

As we've searched your forge, a reference we best guessed for context: https://github.com/ansible/ansible-lint/pull/4216/files/1b424b5122b3158df808fcde4bdd40c40474dc49#diff-ade5ce2a08eeaf42cfeb0027865a0b7cd2c987da9af081d6604ce9d937d13bd0L146-L148

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Roadmap

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions