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
Setting a variable to default(omit) sets it to a string placeholder instead of undefined #44261
Comments
Files identified in the description: If these files are inaccurate, please update the |
Files identified in the description: If these files are inaccurate, please update the |
|
This is the expected behavior.
It is not designed to leave a variable undefined. The documentation describes it as:
There is actually no way to define a variable as undefined. The act of defining it, will always define it, regardless of your value. You will need to use additional logic to handle your situation. If you have further questions please stop by IRC or the mailing list:
|
The string "__omit_place_holder__5ebe2a97fd59a2b8a8f0f9772e8e675496a74faa" is expected behavior? What user could possibly expect that?
That's a problem. "Defining an undefined variable" sounds like a strange use case, but it's not, for example, if you just want to copy one variable to another, especially a dictionary: keys that were not in the input dictionary should not be in the output one. |
omit is not for 'undefining variables' it is for 'omitting' action options, as such its is hard to meet 'expectations' when it is being misused. If you want to 'null' a variable, this can be done (yaml ~ or python None will work), but you cannot 'undefine' it. Still, this would be a 'feature' request, not a bug, but considering that the underlying technologies used also don't permit this, it is not something trivial to implement. |
Looks like there is already a feature request for this: #22417 (I couldn't find it before). I would say that the current behaviour is still a bug, regardless of what happens with that feature request. If using |
we cannot know how you will use a variable until the play has ended, by that time that information is irrelevant. So having omit value in a variable is not incorrect nor wrong, the usage of it might be, but that is not something we can know at the time of the value assignment. |
I see what you're saying, but seeing the string value "__omit_place_holder__5ebe2a97fd59a2b8a8f0f9772e8e675496a74faa" is never the expected behaviour. I ran into this again yesterday where I tried something similar with the "mode" variable of the "file" module. What happened was that the mode was simply left unchanged (instead of the It's hard to know without digging into the implementation, but surely you can detect when the variable is being evaluated to its string value and that string value is the omit placeholder? Even if you error after the play has ended that's much better than silently getting the wrong result, as I did with the mode, so no, I don't think it's "irrelevant". |
SUMMARY
When I set a variable to
anothervariable | default(omit)
andanothervariable
is undefined I expect the result to be undefined, but instead it's set to a string placeholder ("__omit_place_holder__SOMEGUID").ISSUE TYPE
COMPONENT NAME
Jinja2 expressions?
ANSIBLE VERSION
CONFIGURATION
No changes
OS / ENVIRONMENT
Ubuntu 16.04
STEPS TO REPRODUCE
EXPECTED RESULTS
ACTUAL RESULTS
The text was updated successfully, but these errors were encountered: