jinja_trim_blocks and jinja_lstrip_blocks Seem to Break Formulas #67304
Replies: 26 comments 1 reply
-
| Just to verify its not the sls files in combination with the jinja settings, can you try cloning that repo to your local file_roots and see if it works then versus the gitfs? I know you state that your local state files work fine but I want to make sure whether the users-formulas states are the issue or gitfs. Thanks | 
Beta Was this translation helpful? Give feedback.
-
| Can do. I'll try it and report back. | 
Beta Was this translation helpful? Give feedback.
-
| So, I tried the following: 
 In both cases, I get the same errors as above. So GitFS and  | 
Beta Was this translation helpful? Give feedback.
-
| Is there any other information you need? | 
Beta Was this translation helpful? Give feedback.
-
| ping? | 
Beta Was this translation helpful? Give feedback.
-
| @Ch3LL do you need any other info for this issue? Would this be better-suited to be opened against the saltstack-formulas org? | 
Beta Was this translation helpful? Give feedback.
-
| @bnied okay I believe what is going on is related to how jinja handles  Accordign to the jinja docs here: 
 This whitespace includes newlines And in combination with those two jinja settings. according to the docs those do the following: 
 so I'm thinking this might be expected behavior, but can you please test one thing for me. Can you clone that repo down and then remove the  | 
Beta Was this translation helpful? Give feedback.
-
| Can do! I'll try this either today or this weekend, and have feedback back to you by Monday. | 
Beta Was this translation helpful? Give feedback.
-
| I'm seeing the same problem. We have in our environment set jinja_trim_blocks and jinja_lstrip_blocks to true. At this point it would be very painful to turn them off. I am hoping that there is a way to turn them off on a per file basis so that I can take advantage of the users formula without having to re do all of our templates, etc. that are dependent on that jinja behavior. | 
Beta Was this translation helpful? Give feedback.
-
| This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue. | 
Beta Was this translation helpful? Give feedback.
-
| I believe this issue needs to be reopened. Here is another example of it breaking formulas (the issue and the PR that resolved it): 
 Please also note my comment regarding the fix, since it resulted in other side effects. | 
Beta Was this translation helpful? Give feedback.
-
| as per my most recent comment i believe this is expected behavior and not an issue with salt, but expected behavior with how jinja is rendered with these options. | 
Beta Was this translation helpful? Give feedback.
-
| @Ch3LL Thanks for your response.  I agree, from a Jinja perspective, that this is expected behaviour.  However, the Jinja doesn't respect the surrounding YAML, which needs to be kept sane via. Salt.  Whether the master has been configured to use  
 Ansible has this feature as shown in the quotes below. ansible/ansible#10725 (comment): 
 ansible/ansible#10725 (comment): 
 I've tried all sorts of incantations of this to see if it is already supported by SaltStack but that doesn't seem to be the case.  It would be really helpful if it was, so that SaltStack formulas can explicitly state the settings to use, so that the rendering is consistent, whether  | 
Beta Was this translation helpful? Give feedback.
-
| are you using version >=2018.3.0? I re-looked at the documentation for these options and they have been deprecated as you can see here: https://docs.saltstack.com/en/latest/ref/configuration/master.html#jinja-trim-blocks 
 and here is the docs for jinja_env: https://docs.saltstack.com/en/latest/ref/configuration/master.html#jinja-env and jinja_sls_env: https://docs.saltstack.com/en/latest/ref/configuration/master.html#std:conf_master-jinja_sls_env I'm guessing you might be on the updated version of salt. Do those options work for you? | 
Beta Was this translation helpful? Give feedback.
-
| @Ch3LL Thanks for your feedback. Actually, I had noticed that and have already tried the newly introduced method, using the example mentioned in the issue I linked to earlier (saltstack-formulas/postgres-formula#241): jinja_env:
  trim_blocks: True
  lstrip_blocks: TrueThe problem remains as expected, since what's really required is something like Ansible's per-file override (as mentioned above). As formula writers, we cannot guarantee the configuration of the salt masters out there. With the per-file override, we will be able to explicitly state how the Jinja renderer should handle whitespace for that specific file. | 
Beta Was this translation helpful? Give feedback.
-
| thanks for follow up. I will go ahead and re-open this as a feature request | 
Beta Was this translation helpful? Give feedback.
-
| Thank you for updating this issue. It is no longer marked as stale. | 
Beta Was this translation helpful? Give feedback.
-
| @Ch3LL Thanks, appreciate it. | 
Beta Was this translation helpful? Give feedback.
-
| This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue. | 
Beta Was this translation helpful? Give feedback.
-
| Still a problem. | 
Beta Was this translation helpful? Give feedback.
-
| Thank you for updating this issue. It is no longer marked as stale. | 
Beta Was this translation helpful? Give feedback.
-
| I'd love to see a per-file override as well so that we can do something like: 
 Managing whitespace for network device configs without it is painful, and I can't enable: globally because it would break a dozen or more formulas I'm using. | 
Beta Was this translation helpful? Give feedback.
-
| https://github.com/ansible/ansible/blob/devel/lib/ansible/template/__init__.py#L921 this is how ansible implements this, sadly they're gpl3 and we're apache2 so we can't use their code. Eyes only. A solution would be nice though, this can't be a global setting. | 
Beta Was this translation helpful? Give feedback.
-
| I've just implemented a version of the ansible per-file settings thingy like this: Since the Ansible code is of an incompatible license I figured I'd reimplement it as easily as possible. What we do is: 
 The patch is based off 3005.1, since that's what's building in my Nix infrastructure at the moment. I'll look into upstreaming "this" (something like this) :) | 
Beta Was this translation helpful? Give feedback.
-
| @Ch3LL It's been seven years and no progress :( Please, this would be really useful.. | 
Beta Was this translation helpful? Give feedback.
-
| To be fair, there is some progress. There's an outstanding PR that needs a little love and then it should be merge ready. I'll see if I can spend some time on it in a couple weeks. | 
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description of Issue/Question
When using our in-house Salt tree,
jinja_trim_blocksandjinja_lstrip_blocksboth work without issue. However, if I then enable a GitFS-backed Saltstack formula, things start breaking spectacularly.For example, when trying to use the users-formula, if you have
jinja_trim_blocksenabled:(please note that the dash in the user and group aren't present in the actual user or group)
Alternatively, when
jinja_lstrip_blocksis enabled:Removing these two options allow the Salt Formulas to work normally.
Setup
/etc/salt/master:Steps to Reproduce Issue
Run Salt after configuring as noted above.
Versions Report
Master and all minions are running the same version.
Beta Was this translation helpful? Give feedback.
All reactions