ampersand in a if else code block

184 views
Skip to first unread message

JM

unread,
Jun 11, 2014, 9:57:34 AM6/11/14
to salt-...@googlegroups.com
I am looking to make a determination if two lists have common elements.

This works in a pure Python
>>> listA = [1,2,3]
>>> listB = [3,4,5]
>>> set(listA) & set(listB)
set([3])

In a sls file:
{% set listA=[1,2,3] %}
{% set listB=[3,4,5] %}
{% if set(listA) & set(listB) %}
  # Do something
{% endif %}

Jinja complains: Jinja syntax error: unexpected char u'&'

Some Jinja docs mentioned {{ variable|safe }| or {{ variable|e }} but neither seems work in a code block.

Does anyone know if this is possible? Thanks.

nathan tech

unread,
Jun 11, 2014, 1:44:14 PM6/11/14
to salt-...@googlegroups.com
Is there a reason why we have to use Jinja? I don't have the patience to learn a whole new templating engine just to do some dev ops. Why couldn't they just use Python instead of Jinja? I am not looking forwarding to using Salt after looking at the Jinja site. I think I will steer clear of Jinja as much as I can.

Arnold Bechtoldt

unread,
Jun 11, 2014, 1:51:55 PM6/11/14
to salt-...@googlegroups.com
> Why
> couldn't they just use Python instead of Jinja?

Just RTFM. :)

http://docs.saltstack.com/en/latest/ref/renderers/all/index.html

--
Arnold Bechtoldt

Karlsruhe, Germany

On 11.06.14 19:44, nathan tech wrote:
> Is there a reason why we have to use Jinja? I don't have the patience to
> learn a whole new templating engine just to do some dev ops. Why
> couldn't they just use Python instead of Jinja? I am not looking
> forwarding to using Salt after looking at the Jinja site. I think I will
> steer clear of Jinja as much as I can.
>
> On Wednesday, June 11, 2014 9:57:34 AM UTC-4, JM wrote:
>
> I am looking to make a determination if two lists have common elements.
>
> This works in a pure Python
> >>> listA = [1,2,3]
> >>> listB = [3,4,5]
> >>> set(listA) & set(listB)
> set([3])
>
> In a sls file:
> {% set listA=[1,2,3] %}
> {% set listB=[3,4,5] %}
> {% if set(listA) & set(listB) %}
> # Do something
> {% endif %}
>
> Jinja complains: *Jinja syntax error: unexpected char u'&'*
>
> Some Jinja docs mentioned {{ variable|safe }| or {{ variable|e }}
> but neither seems work in a code block.
>
> Does anyone know if this is possible? Thanks.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Salt-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to salt-users+...@googlegroups.com
> <mailto:salt-users+...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.
0xE2356889.asc
signature.asc

JM

unread,
Jun 12, 2014, 3:44:28 PM6/12/14
to salt-...@googlegroups.com
Arnold,

This seems to work. Do you or anyone by any chance know if I can create a pillar/_modules/ folder like file/_modules/? I wish import a home-made module?

Thank you.

JM.

Seth House

unread,
Jun 13, 2014, 12:31:17 AM6/13/14
to salt-...@googlegroups.com

On Jun 12, 2014 1:44 PM, "JM" <jin...@gmail.com> wrote:
> This seems to work. Do you or anyone by any chance know if I can create a pillar/_modules/ folder like file/_modules/? I wish import a home-made module?

For master-side modules (since Pillar is complied on the master), create a directory and point your extension_modules setting at it. That dir can contain sub-dirs for any of Salts module types (modules, states, runners, etc) and will be loaded on the master.

Seth House

unread,
Jun 13, 2014, 12:46:25 AM6/13/14
to salt-...@googlegroups.com

Nathan, as Arnold pointed out Salt has a pluggable system and Jinja/yaml is just the default. We have not one but THREE Python-based alternatives. :-)

Salt states only care about the data structure and not what generates it.

--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages