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

Revert "[bootstrap] fix: fixed required variable validation assertion" #1076

Merged
merged 1 commit into from
Dec 8, 2023
Merged

Revert "[bootstrap] fix: fixed required variable validation assertion" #1076

merged 1 commit into from
Dec 8, 2023

Conversation

gregmulvaney
Copy link
Contributor

Reverts #1074

I made a mistake on testing this PR.

The Jinja default() filter does not play nice with boolean variables. Any false-y variables ( e.g. bootstrap_ipv6_enabled: false ) will fail the assertion.

Without setting the default filters boolean paramater to true the filters scope is limited strictly to Undefined which Ansible does not seem to assign to variables that are... undefined.

def do_default(value, default_value=u'', boolean=False):
    """If the value is undefined it will return the passed default value,
    otherwise the value of the variable:

    .. sourcecode:: jinja

        {{ my_variable|default('my_variable is not defined') }}

    This will output the value of ``my_variable`` if the variable was
    defined, otherwise ``'my_variable is not defined'``. If you want
    to use default with variables that evaluate to false you have to
    set the second parameter to `true`:

    .. sourcecode:: jinja

        {{ ''|default('the string was empty', true) }}
    """
    if isinstance(value, Undefined) or (boolean and not value):
        return default_value
    return value

@github-actions github-actions bot added the area/bootstrap Changes made in the bootstrap directory label Dec 8, 2023
@onedr0p
Copy link
Owner

onedr0p commented Dec 8, 2023

Thanks for looking into this, bummer it doesn't play the way we want it to.

@onedr0p onedr0p merged commit 123cdbf into onedr0p:main Dec 8, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/bootstrap Changes made in the bootstrap directory
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants