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

jinja[invalid] error when using vars on a task #2569

Closed
branic opened this issue Oct 8, 2022 · 0 comments · Fixed by #2588
Closed

jinja[invalid] error when using vars on a task #2569

branic opened this issue Oct 8, 2022 · 0 comments · Fixed by #2588
Assignees
Labels
Milestone

Comments

@branic
Copy link
Contributor

branic commented Oct 8, 2022

Summary

A task where the module directives are using jinja templating and the task has a vars directive that define variables used in the jinja templating causes a jinja[invalid] error to be reported.

Issue Type
  • Bug Report
Ansible and Ansible Lint details
ansible --version
ansible [core 2.13.4]
  config file = None
  configured module search path = ['/home/bevans/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/bevans/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/bevans/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/bevans/.local/bin/ansible
  python version = 3.10.7 (main, Sep  7 2022, 00:00:00) [GCC 12.2.1 20220819 (Red Hat 12.2.1-1)]
  jinja version = 3.0.3
  libyaml = True

ansible-lint --version
ansible-lint 6.8.0 using ansible 2.13.4
  • ansible installation method: pip
  • ansible-lint installation method: pip
OS / ENVIRONMENT

Fedora 36

Also verified using the quay.io/ansible/creator-ee:v0.9.2 container image

STEPS TO REPRODUCE

Task Definition causing failure:

- name: Create namespace
  kubernetes.core.k8s:
    host: "{{ __aap_ocp_install_auth_results['openshift_auth']['host'] }}"
    api_key: "{{ __aap_ocp_install_auth_results['openshift_auth']['api_key'] }}"
    validate_certs: "{{ aap_ocp_install_ocp_connection['validate_certs'] | default(omit) }}"
    state: present
    resource_definition: "{{ lookup('ansible.builtin.template', 'namespace.yaml.j2', template_vars=ns_vars) | from_yaml }}"
    apply: true
  vars:
    ns_vars:
      ns_name: "{{ aap_ocp_install_namespace }}"
Desired Behavior

The above task should not generate a jinja[invalid] error

Actual Behavior

Please give some details of what is actually happening.
Include a minimum complete verifiable example with:

  • playbook
  • output of running ansible-lint
  • if you're getting a stack trace, output of
    ansible-playbook --syntax-check playbook
$ ansible-lint --profile=production roles/aap_ocp_install/tasks/initialization.yml 
WARNING  Listing 1 violation(s) that are fatal
roles/aap_ocp_install/tasks/initialization.yml:13: jinja[invalid]: An unhandled exception occurred while running the lookup plugin 'ansible.builtin.template'. Error was a <class 'ansible.errors.AnsibleError'>, original message: Unhandled exception when retrieving template_vars:
'ns_vars' is undefined. 'ns_vars' is undefined. Unhandled exception when retrieving template_vars:
'ns_vars' is undefined. 'ns_vars' is undefined
You can skip specific rules or tags by adding them to your configuration file:
# .config/ansible-lint.yml
warn_list:  # or 'skip_list' to silence them completely
  - jinja[invalid]  # Rule that looks inside jinja2 templates.

              Rule Violation Summary               
 count tag            profile rule associated tags 
     1 jinja[invalid] basic   formatting           

Failed after min profile: 1 failure(s), 0 warning(s) on 1 files.
@branic branic added bug new Triage required labels Oct 8, 2022
@ssbarnea ssbarnea self-assigned this Oct 10, 2022
@ssbarnea ssbarnea removed the new Triage required label Oct 10, 2022
@ssbarnea ssbarnea added this to the 6.8.x milestone Oct 10, 2022
ssbarnea added a commit to ssbarnea/ansible-lint that referenced this issue Oct 10, 2022
ssbarnea added a commit that referenced this issue Oct 10, 2022
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