-
Notifications
You must be signed in to change notification settings - Fork 671
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
jinja[invalid] incorrectly fires for missing mandatory var when defined in loop_var #3048
jinja[invalid] incorrectly fires for missing mandatory var when defined in loop_var #3048
Comments
It's not just loops, there are other false positives that emit
---
- name: Update Jenkins plugins
hosts: "all"
tasks:
- name: Initialize plugins_list fact
ansible.builtin.set_fact:
plugins_list: []
# Add plugins etc; these tasks have been omitted
- name: Generate jenkins-plugins.yml file
delegate_to: localhost
ansible.builtin.copy:
dest: "{{ plugins_file }}"
content: >
{{ {'plugins': plugins_list} | to_nice_yaml(indent=2) }}
mode: "0644" This causes
# group_vars/all.yml
host_info_keys:
cpus: "{{ vsphere_guest_cpu_sockets }}"
memory: "{{ vsphere_guest_memory_mb }}" # A task file that belongs to a role
- name: Write host info file
delegate_to: localhost
ansible.builtin.copy: # noqa template-instead-of-copy
dest: "{{ host_info_dir }}/{{ inventory_name }}/{{ inventory_hostname }}.yml"
content: "{{ host_info_keys | to_nice_yaml(explicit_start=True, sort_keys=False) }}"
mode: "0644" Again, fails with Another frustrating part of this bug is that it can't be suppressed on the exact line with a multi-line YAML statement. So in second example above, this suppression does not work: - name: Write host info file
delegate_to: localhost
ansible.builtin.copy: # noqa template-instead-of-copy
dest: "{{ host_info_dir }}/{{ inventory_name }}/{{ inventory_hostname }}.yml"
content: >- # noqa jinja[invalid]
{{ host_info_keys | to_nice_yaml(explicit_start=True, sort_keys=False) }}
mode: "0644" The only way to suppress it in this case is on the task level, like so: - name: Write host info file # noqa jinja[invalid]
delegate_to: localhost
ansible.builtin.copy: # noqa template-instead-of-copy
dest: "{{ host_info_dir }}/{{ inventory_name }}/{{ inventory_hostname }}.yml"
content: "{{ host_info_keys | to_nice_yaml(explicit_start=True, sort_keys=False) }}"
mode: "0644" |
Summary
Recent changes have meant that
jinja[invalid]
is firing for mandatory values where the variable is defined in loop control. I've included my slimmed down playbook below which should make things clearer.There are no errors on v6.12.2 and I cannot see anything that would directly have affected this in the changelog. I believe this to be a regression.
Issue Type
OS / ENVIRONMENT
STEPS TO REPRODUCE
Desired Behavior
Expected no linting errors to show as per previous ansible-lint version.
Actual Behavior
There is a linting error on junja[invalid] when the above should be
The text was updated successfully, but these errors were encountered: