saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Install Salt from the Salt package repositories here:
https://docs.saltproject.io/salt/install-guide/en/latest/
Apache License 2.0
14.22k stars 5.49k forks source link

salt.renderers.jinja with (false) option only renders 1 level correctly #38862

Open leonkatz opened 7 years ago

leonkatz commented 7 years ago

Description of Issue/Question

without (false) option

gitfs_saltenv:
                   [{sdev: [{ref: master}]}]

with (false) option

gitfs_saltenv:
    - sdev:
    - ref: master

Expected

 gitfs_saltenv:
    - sdev:
      - ref: master

Setup

(Please provide relevant configs and/or SLS files (Be sure to remove sensitive info).)

pillar.sls
      gitfs_saltenv:
        - sdev:
           - ref: master
state.sls
gitfs_saltenv:
  {{ remote.gitfs_saltenv|yaml(false) }}

Steps to Reproduce Issue

(Include debug logs if possible and relevant.)

Versions Report

(Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)

root@salt-master-dev:/home/ubuntu# salt --versions-report
Salt Version:
           Salt: 2016.11.0

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 1.5
          gitdb: 0.5.4
      gitpython: 0.3.2 RC1
          ioflo: Not Installed
         Jinja2: 2.7.2
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 0.9.1
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: 1.2.3
      pycparser: Not Installed
       pycrypto: 2.6.1
         pygit2: Not Installed
         Python: 2.7.6 (default, Jun 22 2015, 17:58:13)
   python-gnupg: Not Installed
         PyYAML: 3.10
          PyZMQ: 14.0.1
           RAET: Not Installed
          smmap: 0.8.2
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.0.5

System Versions:
           dist: Ubuntu 14.04 trusty
        machine: x86_64
        release: 4.4.0-34-generic
         system: Linux
        version: Ubuntu 14.04 trusty
leonkatz commented 7 years ago

2 spaces- ref: master Github markup is not displaying the spaces, just like the renderer is not doing it.

gtmanfred commented 7 years ago

If you wrap the code block in triple backtics, it markdown will not modify your issue.

Can you make sure that I have updated the initial comment to display what you were trying to how?

Thanks, Daniel

leonkatz commented 7 years ago

Thanks for you help. Updated with the correct info.

leonkatz commented 7 years ago

Is this still blocked?

gtmanfred commented 7 years ago

What is the remote here?

state.sls
gitfs_saltenv:
  {{ remote.gitfs_saltenv|yaml(false) }}

I do not see it anywhere in your setup?

gtmanfred commented 7 years ago

I have been able to replicate this issue with the following setup.

[root@salt ~]# tail -c +0 /srv/*/*.sls
==> /srv/pillar/test.sls <==
remote:
  gitfs_saltenv:
    - sdev:
      - ref: master

==> /srv/pillar/top.sls <==
base:
  '*':
    - test

==> /srv/salt/test.sls <==
gitfs_saltenv:
  {{ pillar.remote.gitfs_saltenv|yaml(false) }}

The output with yaml(false) does not indent the ordered dictionary correctly.

[root@salt ~]# salt-call cp.get_template salt://test.sls /test template=jinja
local:
    /test
[root@salt ~]# cat /test
gitfs_saltenv:
  - sdev:
  - ref: master

Which means that the file renders to json like this.

{
  "gitfs_saltenv": [
    {
      "sdev": null
    },
    {
      "ref": "master"
    }
  ]
}

Instead of this

{
  "gitfs_saltenv": [
    {
      "sdev": [
        {
          "ref": "master"
        }
      ]
    }
  ]
}

The work around would be to just not set yaml(false) and use the default, which will print it out in json format, but also renders it correctly for later use.

Thanks for reporting. Daniel

leonkatz commented 7 years ago

I think I have more specifics on the issue. I found another symptom. Starting yaml

A:
  B:
    C:
    C:
    C:
    C:

After yaml filter

A:
  B:
    C:
  C:
  C:
  C:
gtmanfred commented 7 years ago

Please surround them by triple backtics so that the spacing appears correctly

On Sat, Feb 25, 2017 at 12:37 AM leonkatz notifications@github.com wrote:

I think I have more specifics on the issue. I found another symptom. Starting yaml A: B: C: C: C: C:

After yaml filter A: B: C: C: C: C:

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/saltstack/salt/issues/38862#issuecomment-282464793, or mute the thread https://github.com/notifications/unsubscribe-auth/AAssoZBiyHRU2_qvQCA7Xfzcbimzu6dOks5rf8wwgaJpZM4LqPnZ .

leonkatz commented 7 years ago

for above, it seems that the yaml filter just doesn't work after the second line of indentation of repeating indentation, but keeps previous indentation.

forty8bits commented 7 years ago

Any updates on this? We're experience this issue as well. For example, given the following Pillar data:

elasticsearch:
  config:
    bootstrap.memory_lock: true
    network.host:
      - _local_
      - _site_

Used like so:

elasticsearch_configured:
  file.managed:
    - name: /etc/elasticsearch/elasticsearch.yml
    - contents: |
        {{ elasticsearch.config|yaml(False)|indent(8) }}

The contents are incorrectly rendered as:

bootstrap.memory_lock: true
network.host:
- _local_
- _site_

Note the missing indentation of the network.host list items.

sokratisg commented 6 years ago

Any update?

gtmanfred commented 6 years ago

for @forty8bits technically

bootstrap.memory_lock: true
network.host:
- _local_
- _site_

Is correct yaml, you do not need any more indentation on list items there. They will appear inside of network.host.

screen shot 2018-03-30 at 12 49 35 pm

And anyone else asking for an update, it is marked as a bug, but no one is currently working on this as there are hire priority issues. Any PR would be greatly appreciated.

aarnaud commented 6 years ago

+1

hajdukd commented 5 years ago

+1

stale[bot] commented 4 years ago

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.

stale[bot] commented 4 years ago

Thank you for updating this issue. It is no longer marked as stale.

jmhostalet commented 3 years ago

any update on this bug ?