diff --git a/examples/playbooks/rule-deprecated-bare-vars-fail.yml b/examples/playbooks/rule-deprecated-bare-vars-fail.yml index 7091f4693ce..a7efeea3e4d 100644 --- a/examples/playbooks/rule-deprecated-bare-vars-fail.yml +++ b/examples/playbooks/rule-deprecated-bare-vars-fail.yml @@ -39,12 +39,6 @@ msg: "{{ item }}" with_dict: my_dict - ### Testing with_dict with a default empty dictionary - - name: Use with_dict loop using variable and default - ansible.builtin.debug: - msg: "{{ item.key }} - {{ item.value }}" - with_dict: uwsgi_ini | default({}) - - name: Use with_nested loop using bare variable ansible.builtin.debug: msg: "{{ item.0 }} {{ item.1 }}" diff --git a/examples/playbooks/rule-deprecated-bare-vars-pass.yml b/examples/playbooks/rule-deprecated-bare-vars-pass.yml index c7e65217f89..fe3ca1d6419 100644 --- a/examples/playbooks/rule-deprecated-bare-vars-pass.yml +++ b/examples/playbooks/rule-deprecated-bare-vars-pass.yml @@ -166,3 +166,12 @@ with_items: >- {%- set ns = [1, 1, 2] -%} {{- ns.keys | unique -}} + + - name: Reproduce bug 3646 + ansible.builtin.file: + path: "{{ item.path }}" + state: directory + mode: "{{ item.mode }}" + with_community.general.filetree: + - "../templates/SpaceVim.d/" + when: item.state == "directory" and ".git" not in item.path diff --git a/src/ansiblelint/rules/deprecated_bare_vars.py b/src/ansiblelint/rules/deprecated_bare_vars.py index 1756e926dfc..a2765f8d666 100644 --- a/src/ansiblelint/rules/deprecated_bare_vars.py +++ b/src/ansiblelint/rules/deprecated_bare_vars.py @@ -27,7 +27,7 @@ from typing import TYPE_CHECKING, Any from ansiblelint.rules import AnsibleLintRule -from ansiblelint.text import has_glob, has_jinja +from ansiblelint.text import has_glob, has_jinja, is_fqcn_or_name if TYPE_CHECKING: from ansiblelint.file_utils import Lintable @@ -84,7 +84,11 @@ def _matchvar( task: dict[str, Any], loop_type: str, ) -> bool | str: - if isinstance(varstring, str) and not has_jinja(varstring): + if ( + isinstance(varstring, str) + and not has_jinja(varstring) + and is_fqcn_or_name(varstring) + ): valid = loop_type == "with_fileglob" and bool( has_jinja(varstring) or has_glob(varstring), ) @@ -121,4 +125,4 @@ def test_use_bare_negative() -> None: failure = "examples/playbooks/rule-deprecated-bare-vars-fail.yml" bad_runner = Runner(failure, rules=collection) errs = bad_runner.run() - assert len(errs) == 12 + assert len(errs) == 11