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

ansible-lint reports The 'changed' test expects a dictionary for facts set in different playbook file #3155

Closed
mprasil opened this issue Mar 8, 2023 · 0 comments · Fixed by #3157
Assignees
Labels

Comments

@mprasil
Copy link

mprasil commented Mar 8, 2023

Summary

ansible-lint reports failure with fact not being dictionary when the fact is set in some other file:

jinja[invalid]: The 'changed' test expects a dictionary
debugmsg.yaml:4 Task/Handler: Debug message
Issue Type
  • Bug Report
OS / ENVIRONMENT
ansible-lint --version
ansible-lint 6.14.1 using ansible 2.14.3
  • ansible installation method: pip
  • ansible-lint installation method: pip
STEPS TO REPRODUCE

Playbooks:

# playbook.yaml
---
- name: Reproduce bug
  hosts: localhost
  gather_facts: false
  tasks:
  - name: Maybe change something
    ansible.builtin.command:
      cmd: date
    register: date_cmd

  - ansible.builtin.include_tasks: debugmsg.yaml
# debugmsg.yaml
---
- name: Debug message
  ansible.builtin.debug:
    msg: "Is changed:{{ date_cmd is changed }}"

Then run lint command:

ansible-lint playbook.yaml

Which reports following failure:

jinja[invalid]: The 'changed' test expects a dictionary
debugmsg.yaml:4 Task/Handler: Debug message

(Some other failures are also reported due to the example being intentionally minimal here)

If the two tasks were in the same playbook, like bellow, ansible-lint does not report this failure:

---
- name: Reproduce bug
  hosts: localhost
  gather_facts: false
  tasks:
  - name: Maybe change something
    ansible.builtin.command:
      cmd: date
    register: date_cmd

  - name: Debug message
    ansible.builtin.debug:
      msg: "Is changed:{{ date_cmd is changed }}"
Desired Behavior

In both scenarios, ansible-lint should not report failure with the fact not being dictionary.

Actual Behavior

When the debug task is in separate file, ansible-lint fails with:

jinja[invalid]: The 'changed' test expects a dictionary
debugmsg.yaml:4 Task/Handler: Debug message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants