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

Salt interpets jinja syntax in contents pillar #33319

Closed
ghost opened this issue May 17, 2016 · 7 comments
Closed

Salt interpets jinja syntax in contents pillar #33319

ghost opened this issue May 17, 2016 · 7 comments
Assignees
Labels
Bug broken, incorrect, or confusing behavior Core relates to code central or existential to Salt Documentation Relates to Salt documentation fixed-pls-verify fix is linked, bug author to confirm fix P3 Priority 3 severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Milestone

Comments

@ghost
Copy link

ghost commented May 17, 2016

I have a situation where I want to use contents_pillar within the file.managed module to create consul-template templates.

However, consul-template shares a subset of its syntax with Jinja. This means that contents_pillar does not escape the contents of the pillar on output and any occurrences of {{ }} are interpreted as Jinja syntax:

tmpl:
  - |
    job "example-job" {
      ...

      task "example" {
          driver = "docker"

          config {
              image = "docker-registry.service.consul:5000/example-job:{{key "nomad/jobs/exmaple-job/version"}}"
      ...

However it appears that this can be avoided with raw blocks in Jinja:

tmpl:
  - |
    {% raw %}
    job "example-job" {
      ...

      task "example" {
          driver = "docker"

          config {
              image = "docker-registry.service.consul:5000/example-job:{{key "nomad/jobs/exmaple-job/version"}}"
      ...
      {% endraw %}

That said this feels like kind of a hack. Would it be possible to pass an option to file.managed that wraps the content (or content_pillar) in a raw block?

@Ch3LL
Copy link
Contributor

Ch3LL commented May 18, 2016

@grobinson-blockchain {% raw %} is intended for this exact use case to escape jinja. It would not be possible in this particular use case to allow file.managed to manage these raw blocks because the jinja in the pillar would be rendered before file.managed is ever called.

Another approach you could take if you do not like specifying {% raw %} is to possibly use a different renderer.

@Ch3LL Ch3LL added the Pending-Discussion The issue or pull request needs more discussion before it can be closed or merged label May 18, 2016
@Ch3LL Ch3LL added this to the Blocked milestone May 18, 2016
@ghost
Copy link
Author

ghost commented May 19, 2016

@Ch3LL thanks for replying! Is this referenced in the docs at all? If not, I think that would be very useful as I can't be the only person trying to use pillars int this way!

@Ch3LL
Copy link
Contributor

Ch3LL commented May 21, 2016

@grobinson-blockchain hmmm i actually can't find an instance of us documenting {% raw %}. Although it is on jinjas documentation here I think its a great idea to get this added to our jinja docs though!

@Ch3LL Ch3LL added Documentation Relates to Salt documentation Bug broken, incorrect, or confusing behavior P3 Priority 3 and removed Pending-Discussion The issue or pull request needs more discussion before it can be closed or merged labels May 21, 2016
@Ch3LL Ch3LL modified the milestones: Approved, Blocked May 21, 2016
@Ch3LL Ch3LL added severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around Core relates to code central or existential to Salt labels May 21, 2016
@ghost
Copy link
Author

ghost commented May 21, 2016

@Ch3LL that would be great!

Although it is on jinjas documentation here I think its a great idea to get this added to our jinja docs though!

I think the issue for most people would be making the connection that they can use Jinja {% raw %} blocks as above to solve their similar problem. Putting this in the docs make it explicit but it also reassures people that this is the recommended way to solve this issue.

@rallytime
Copy link
Contributor

I've added some docs about this in #33513.

@rallytime rallytime added fixed-pls-verify fix is linked, bug author to confirm fix TEAM Core labels May 25, 2016
@rallytime rallytime modified the milestones: C 9, Approved May 25, 2016
@rallytime rallytime self-assigned this May 25, 2016
@Ch3LL
Copy link
Contributor

Ch3LL commented Jun 2, 2016

@grobinson-blockchain are you okay closing this issue?

@ghost
Copy link
Author

ghost commented Jun 3, 2016

@Ch3LL yep!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior Core relates to code central or existential to Salt Documentation Relates to Salt documentation fixed-pls-verify fix is linked, bug author to confirm fix P3 Priority 3 severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Projects
None yet
Development

No branches or pull requests

2 participants