-
-
Notifications
You must be signed in to change notification settings - Fork 604
Add list of raw_vars whose values are auto-escaped #615
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
Conversation
Variables with randomly generated values risk having opening jinja delimiters
such as `{{` and `{%`, causing templating failures. The new list of `raw_vars`
is a user-configurable method to wrap variable values in `{% raw %}`.
|
This is good but think I'd rather skip all the wildcard stuff for now. It's currently unused by default and not sure it's worth the potential hassle. |
|
We wouldn't want the wildcard functionality to become a wildcard of its own. Surprises not welcome. But to explain, the wildcard functionality stemmed from development on #614 with its new var: This var would require the wildcard, a la: |
|
|
||
| def raw_vars(self, host, hostvars): | ||
| if 'raw_vars' not in hostvars: | ||
| return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it's better to move the default vars into here.
Pros: users shouldn't have to worry about these too much so they are kept out of the way and harder to mess up.
Cons: to disable them would require raw_vars: [] and maybe less visibility?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That "visibility" was my focus. My overarching goal was to transition this functionality from "hidden" -- which for users is possibly surprising and certainly non-configurable -- to "out in the open" and easy to use.
I agree most users won't understand it and won't touch it, in which case they won't mess it up. In that sense, I think it is like neighboring obscure vars in group_vars/all/main.yml, such as wordpress_env_defaults or site_env.
For users who do try to use it, actually adding patterns versus merely disabling it, I think they'll have the easiest time if they readily see the full list of raw_vars default patterns right there in a group_vars file.
Would users really want to adjust patterns? I think a conceivable example would be that someone wants to add an env var in vault_wordpress_sites that should not be wrapped in {% raw %}. They'd need to adjust the raw_vars to be more specific, just wrapping the right parts, such as:
raw_vars:
- vault_wordpress_sites.*.*_password # for `admin_password` (dev only) and `db_password`
- vault_wordpress_sites.*.*_salt
- vault_wordpress_sites.*.*_key
On the other hand, if we decide that visibility and configurability aren't the goal or aren't worth it, then I suppose moving the defaults into vars.py makes sense. In that case, we could consider whether the python code would be "safer" being more targeted to those defaults, not supporting the wildcard stuff and being more "hard-coded" like it has been for WP keys and salts.
|
I incorporated @swalkinshaw's suggested comprehensions; a remarkable streamlining of the code. I added a commit to raise an error if The However, this means that the some_var:
- vault_mail_password
- vault_mysql_root_password
- vault_wordpress_sites
raw_vars: "{{ some_var }}"If a user were to create the unlikely scenario above, I think it would be a baffling surprise/mystery why
I put |
|
Works great 🎉 |
#548 wrapped WP salts/keys in
{% raw %}to avoid templating failures due to values containing opening jinja delimiters{{and{%. This was not user-configurable (no easy way to opt-out of the magic) and it didn't wrap other variables likely to have randomly generated values, leaving the potential for problematic jinja delimiters.This PR replaces the #548 method with a new list of
raw_varsas a user-configurable method to wrap chosen variable values in{% raw %}.This doesn't seem to be a very risky use of the potentially evolving Ansible plugin API. The only new API material introduced is the checking of Ansible-specific classes
AnsibleMapping,AnsibleSequence, andAnsibleUnicodein theraw_triagemethod. These classes have been around all of Ansible 2.0.To see it work, pull this branch then add the vars below to the end of
group_vars/all/main.yml:Now add this task to the end of the
Determine Remote Userplay inserver.yml:Now run
server.ymlto print the vars, seeing that the stray jinja delimiters don't cause failures: