jinja2 scripting reclass w/SaltStack #6

Closed
inthecloud247 opened this Issue Jul 23, 2013 · 5 comments

Comments

Projects
None yet
2 participants
@inthecloud247

In the readme.Salt file, you mention that "Jinja2-style variables in parameter
values" are currently not working?

Seems like this works with reclass + Ansible currently. Is there anything still blocking reclass + jinja2 with Saltstack?

@madduck

This comment has been minimized.

Show comment
Hide comment
@madduck

madduck Jul 23, 2013

Owner

Yeah, it "works" with Ansible because Ansible itself does Jinja-templating on the variable values, but in doing so it converts everything to strings and loses the type. Having pointed out this issue on the list, I was subsequently kicked out of the community and couldn't send another message (see below). Obviously, the way Ansible does it is not acceptable, but the author doesn't get it.

I am working on interpolation inside reclass, but I am not yet done. Give me another week or two. It'll be much better than what Ansible can do.

Here's my message to the list, which was censored:

Date: Sun, 23 Jun 2013 20:36:21 +0200
From: martin f krafft <madduck@madduck.net>
To: "ansible-project@googlegroups.com" <ansible-project@googlegroups.com>
Subject: Re: [ansible-project] Re: Preserving list objects with Jinja2-style variables

> Types in the playbooks don't matter because all the necessary
> casting happens in the modules.

Try it with 'template':

  ---
  - name: test playbook
    hosts: test_hosts
    gather_facts: no
    vars:
      mylist:
        - 1
        - 2
        - 3
      othervar: '{{mylist}}'
      escaped: \{{mylist}}
      yesno: yes
      notboolean: '{{yesno}}'
    tasks:
      - template: src=test.j2 dest=/tmp/out

And test.j2 just has

  {{mylist.__class__}} {{othervar.__class__}} {{escaped.__class__}}
  {{yesno.__class__}} {{notboolean.__class__}}

in it. You will see that the types are (list, unicode, unicode,
bool, unicode), so there is no casting, actually; the list and
boolean are lost. Everything is converted to unicode, and there is
no way a module can cast that back. Sorry.
Owner

madduck commented Jul 23, 2013

Yeah, it "works" with Ansible because Ansible itself does Jinja-templating on the variable values, but in doing so it converts everything to strings and loses the type. Having pointed out this issue on the list, I was subsequently kicked out of the community and couldn't send another message (see below). Obviously, the way Ansible does it is not acceptable, but the author doesn't get it.

I am working on interpolation inside reclass, but I am not yet done. Give me another week or two. It'll be much better than what Ansible can do.

Here's my message to the list, which was censored:

Date: Sun, 23 Jun 2013 20:36:21 +0200
From: martin f krafft <madduck@madduck.net>
To: "ansible-project@googlegroups.com" <ansible-project@googlegroups.com>
Subject: Re: [ansible-project] Re: Preserving list objects with Jinja2-style variables

> Types in the playbooks don't matter because all the necessary
> casting happens in the modules.

Try it with 'template':

  ---
  - name: test playbook
    hosts: test_hosts
    gather_facts: no
    vars:
      mylist:
        - 1
        - 2
        - 3
      othervar: '{{mylist}}'
      escaped: \{{mylist}}
      yesno: yes
      notboolean: '{{yesno}}'
    tasks:
      - template: src=test.j2 dest=/tmp/out

And test.j2 just has

  {{mylist.__class__}} {{othervar.__class__}} {{escaped.__class__}}
  {{yesno.__class__}} {{notboolean.__class__}}

in it. You will see that the types are (list, unicode, unicode,
bool, unicode), so there is no casting, actually; the list and
boolean are lost. Everything is converted to unicode, and there is
no way a module can cast that back. Sorry.
@madduck

This comment has been minimized.

Show comment
Hide comment
@madduck

madduck Jul 23, 2013

Owner

Oh, btw, I will not add Jinja2 templating to reclass, just pure variable interpolation. This is because Jinja2 itself casts everything to a string, which you don't want (e.g. lists…)

Owner

madduck commented Jul 23, 2013

Oh, btw, I will not add Jinja2 templating to reclass, just pure variable interpolation. This is because Jinja2 itself casts everything to a string, which you don't want (e.g. lists…)

@madduck

This comment has been minimized.

Show comment
Hide comment
@madduck

madduck Aug 7, 2013

Owner

This is now implemented, and I hope it works. It would be awesome if you could poke at it, and possibly suggest improvements to the documentation. Please let me know anything else that comes to your mind.

Owner

madduck commented Aug 7, 2013

This is now implemented, and I hope it works. It would be awesome if you could poke at it, and possibly suggest improvements to the documentation. Please let me know anything else that comes to your mind.

@madduck madduck closed this Aug 7, 2013

@madduck

This comment has been minimized.

Show comment
Hide comment
@inthecloud247

This comment has been minimized.

Show comment
Hide comment
@inthecloud247

inthecloud247 Nov 26, 2013

Ah cool will take a look. Sorry missed this b4.

On Nov 26, 2013, at 1:31 PM, "martin f. krafft" notifications@github.com wrote:

FTR: http://reclass.pantsfullofunix.net/


Reply to this email directly or view it on GitHub.

Ah cool will take a look. Sorry missed this b4.

On Nov 26, 2013, at 1:31 PM, "martin f. krafft" notifications@github.com wrote:

FTR: http://reclass.pantsfullofunix.net/


Reply to this email directly or view it on GitHub.

AndrewPickford pushed a commit to AndrewPickford/reclass that referenced this issue Sep 18, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment