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

[WIP] Allow for lazy evaluation of Jinja2 expressions #56116

Open
wants to merge 2 commits into
base: devel
from

Conversation

Projects
None yet
3 participants
@mkrizek
Copy link
Contributor

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

@mkrizek mkrizek force-pushed the mkrizek:lazy_eval branch from e2a4f10 to 5f697a7 May 7, 2019

@ansibot ansibot removed the small_patch label May 7, 2019

"The conditional check 'some_defined_dict_with_undefined_values is defined' failed.",
self._eval_con,
when, variables)
ret = self._eval_con(when, variables)

This comment has been minimized.

Copy link
@bcoca

bcoca May 7, 2019

Member

this should not change

@bcoca bcoca removed the needs_triage label May 7, 2019

@ansibot ansibot added the stale_ci label May 16, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.