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

Parse ansible '#jinja2:' overrides #114

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mkhon
Copy link

@mkhon mkhon commented May 11, 2023

This change allows to use ansible templates as is

jinja2cli/cli.py Outdated
@@ -262,7 +263,7 @@ def render(template_path, data, extensions, strict=False):
extensions.append(ext)

env = Environment(
loader=FileSystemLoader(os.path.dirname(template_path)),
loader=BaseLoader(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this break if your template does an {% include %} now?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. Corrected

@mattrobenolt
Copy link
Owner

Is there documentation around what this format is? I've never seen this before.

@mkhon
Copy link
Author

mkhon commented May 12, 2023

Is there documentation around what this format is? I've never seen this before.

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/template_module.html

Also, you can override jinja2 settings by adding a special header to template file. i.e. #jinja2:variable_start_string:'[%', variable_end_string:'%]', trim_blocks: False which changes the variable interpolation markers to [% var %] instead of {{ var }}. This is the best way to prevent evaluation of things that look like, but should not be Jinja2.

Basically, any jinja2 environment variables can be set this way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants