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

Allow for lazy evaluation of Jinja2 expressions #56116

Open
wants to merge 11 commits into
base: devel
Choose a base branch
from

Conversation

@mkrizek
Copy link
Contributor

@mkrizek mkrizek commented May 6, 2019

SUMMARY

This will allow for:

- hosts: localhost
  gather_facts: no
  vars:
    foo: "{{ nested_undefined_variable }}"
  tasks:
    - debug:
      when: True or foo

Now, the conditional is evaluated to True. Before, this would fail on foo being undefined although it wasn't necessary to evaluate it.

Also, this changes behavior(!):

- hosts: localhost
  gather_facts: no
  vars:
    foo: "{{ nested_undefined_variable }}"
  tasks:
    - assert:
        that:
          - foo is undefined

Before:

TASK [assert] *****************************************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "The conditional check 'foo is undefined' failed. The error was: error while evaluating conditional (foo is undefined): 'nested_undefined_variable' is undefined"}

Now:

TASK [assert] *******************************************************************************************
ok: [localhost] => {
    "changed": false,
    "msg": "All assertions passed"
}

Related:

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

lib/ansible/template/vars.py

@mkrizek mkrizek changed the title Allow for lazy evaluation of Jinja2 expressions [WIP] Allow for lazy evaluation of Jinja2 expressions May 6, 2019
@ansibot ansibot added the WIP label May 6, 2019
test/units/playbook/test_conditional.py Outdated Show resolved Hide resolved
Loading
@mkrizek mkrizek requested a review from bcoca Nov 20, 2019
@giner
Copy link
Contributor

@giner giner commented Sep 1, 2021

Any plans to move this forward?

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants