Skip to content

Include section on lazy vs eager variable evaluation #2955

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

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

Conversation

GreyGnome
Copy link

This PR adds a new section to the Variables guide titled “Lazy vs. Eager Variable Evaluation”. It expands on the existing documentation around variable precedence by demonstrating the difference between eager and lazy evaluation of variables — specifically comparing set_fact (eager) with vars: (lazy).

It includes a self-contained example that walks through:

How variables set with set_fact are evaluated and fixed at the time they are run, how variables defined in vars: blocks are lazily re-evaluated each time they're referenced, and the effect of --extra-vars on both eager and lazy variables.

Also includes an illustration of variable shadowing — showing that vars: blocks can override some variables but not those set using set_fact (due to variable precedence rules).

The section is placed immediately after Variable Precedence: Where Should I Put a Variable? and before Using Advanced Variable Syntax to provide a natural learning progression from where and how variables are resolved, to when they're evaluated. All code and output are copy/paste testable, and align with live Ansible behavior as Ansible core 2.14.2.

This update aims to clarify a subtle aspect of Ansible variable resolution.

This PR adds a new section to the Variables guide titled “Lazy vs. Eager Variable Evaluation”. It expands on the existing documentation around variable precedence by demonstrating the difference between eager and lazy evaluation of variables — specifically comparing set_fact (eager) with vars: (lazy).

It includes a self-contained example that walks through:

How variables set with set_fact are evaluated and fixed at the time they are run, how variables defined in vars: blocks are lazily re-evaluated each time they're referenced, and the effect of --extra-vars on both eager and lazy variables.

Also includes an illustration of variable shadowing — showing that vars: blocks can override some variables but not those set using set_fact (due to variable precedence rules).

The section is placed immediately after Variable Precedence: Where Should I Put a Variable? and before Using Advanced Variable Syntax to provide a natural learning progression from where and how variables are resolved, to when they're evaluated. All code and output are copy/paste testable, and align with live Ansible behavior as Ansible core 2.14.2.

This update aims to clarify a subtle aspect of Ansible variable resolution.
@ansible-documentation-bot ansible-documentation-bot bot added the new_contributor This PR is the first contribution by a new community member. label Aug 4, 2025
@ansible-documentation-bot
Copy link
Contributor

Thanks for your Ansible docs contribution! We talk about Ansible documentation on Matrix at #docs:ansible.im if you ever want to join us and chat about the docs! We meet on Matrix every Tuesday. See the Ansible calendar for meeting details. We welcome additions to our weekly agenda items too. You can add the dawgs-meeting tag to a forum topic to bring it up at the next meeting.

Corrected reference to ansible_variable_precedence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new_contributor This PR is the first contribution by a new community member.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant