-
Notifications
You must be signed in to change notification settings - Fork 9
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
Errors with undefined scope variables. #2
Comments
This seems like a valid issue, I think we should address it. I think the OP has the right idea but I'd like to see it done with native YAML rather than inventing a new syntax like Maybe making the value of the scope keys more flexible by allowing a hash or a string. So either of these would work, the second uses a default. # without default
scope:
environment: ansible_local.custom.environment
# With default
scope:
environment:
var: ansible_local.custom.environment
default: development The above may be too complicated, I'm not sure, I've played around with the idea of an array because its shorter to express but how would we distinguish between a variable and a string? eg: scope:
environment: [ ansible_local.custom.environment, development ] The above is shorter to express and assumes the first element of the array is a variable and the second is a hard coded string - this can be documented but is it obvious enough? @beddari I think you're using this lookup plugin, any thoughts? |
I think keeping scope configuation just key:value has value due to its simplicity. |
Ok, the error you'll get if you use undefined variables in the scope config looks like this
Not too friendly :) However, instead of trying to implement a mechanism providing defaults, does it not make more sense to just handle this case as it was an unset scope var/empty string?
If we run this specifying an empty value for ansible_does_not_exist it works as I'd expect
and the lookup returns correct data. Haven't looked at the full logic yet as the above ideally shouldn't even set that empty string in the API request. Will try to verify. And this shows that we need tests hehe. |
I think we should classify this as a bug. The plan to fix it is currently to add debug output of all defined scope vars and values, and handle undefined vars the same as an empty string, if possible |
One final question.
In the jerakia.yaml file used for Ansible under the scope section is there a mechanism to attempt relating multiple variables.
What we ended up having in our configuration file was:
What we found was that this ended up generating errors on systems that were missing local facts files that defined environment and location. Knowing this now we have adjusted the behavior of our playbooks but we were wondering if there was a supported mechanism to specifiy default values or other variables to use if one is not defined, i.e. something like the following:
Or
The text was updated successfully, but these errors were encountered: