FAQ
hi,

i've structured some pillar data the following way:

affiliate:
   customer1:
     property1:
       - item1
       - item2
     property2:
       key1: value1
       key2: value2

normally i use that to walk over all affiliates and can access their
properties.

1) now i need to loop through all values of key2 for every customer. how
can i do that? is there any use of wildcards possible?

2) how can i access the first item of property1, while looping through
all customers?

cheers
   pille

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Florian Ermisch at Oct 18, 2014 at 6:46 am
    Hi Pille,

    I assume Jinja-templating here and that you meant "property2" as "key2" is no dict ;)

    {% for customer in salt['pillar.get']('affiliate', {}).keys() %}
    Here is the data for {{ customer }}:
    - - property1's 1st value is {{ salt['pillar.get']('affiliate:{0}:property1'.format(customer) )[0] }}
    - - property2's values are:
       {%- for val in salt['pillar.get']('affiliate:{0}:property2'.format(customer),{}).values() %}
         - {{ val }}
       {%- endfor %}
    {%- endfor %}


    I would probably add stuff like "{% if salt['pillar.get']('affiliate:{0}:property1'.format(customer), False) %}" (maybe even "...is not string and ...is iterable") so missing or malformed Pillar-data won't make the templating fail but maybe you want it to fail if required data is missing.

    Regards, Florian

    Am 17. Oktober 2014 16:37:04 MESZ, schrieb pille <pille+salt+mailinglist@struction.de>:
    hi,

    i've structured some pillar data the following way:

    affiliate:
    customer1:
    property1:
    - item1
    - item2
    property2:
    key1: value1
    key2: value2

    normally i use that to walk over all affiliates and can access their
    properties.

    1) now i need to loop through all values of key2 for every customer.
    how
    can i do that? is there any use of wildcards possible?

    2) how can i access the first item of property1, while looping through
    all customers?

    cheers
    pille

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Pille at Oct 18, 2014 at 12:25 pm
    hi florian, thanks for putting me on the right track.

    i'll just do a summarized follow-up, since i guess what i intended
    wasn't clear.
    On 10/18/2014 08:46 AM, Florian Ermisch wrote:
    {% for customer in salt['pillar.get']('affiliate', {}).keys() %}
    Here is the data for {{ customer }}:
    - property1's 1st value is {{ salt['pillar.get']('affiliate:{0}:property1'.format(customer) )[0] }}
    - property2's values are:
    {%- for val in salt['pillar.get']('affiliate:{0}:property2'.format(customer),{}).values() %}
    - {{ val }}
    {%- endfor %}
    {%- endfor %}
    1) i need a set (list without duplicates) of the values of all key2's
    for all customers.
    i thought of some crazy wildcard selecting magic, but now i'll loop a
    first time over all customers to collect these values and a second time
    over that list to filter duplicates:

    {% set k2 = [] %}
    {% set k2_duplicate = [] %}
    {% for customer in salt['pillar.get']('affiliate', {}).keys() %}
    {% do k2.append( salt['pillar.get'
    ('affiliate:0}:property2:key2'.format(customer),{}) ) %}
    {% endfor %}

    {%- for v in k2 %}
    {%- if v not in k2_duplicate %}
    {%- do k2_duplicate.append(v) %}
    {{ v }}
    {%- endif %}
    {%- endfor %}


    2) [0] accesses single (here the first) elements.

       pille

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Georges Racinet at Oct 18, 2014 at 1:00 pm

    On 10/18/2014 02:25 PM, pille wrote:
    1) i need a set (list without duplicates) of the values of all key2's
    for all customers.
    i thought of some crazy wildcard selecting magic, but now i'll loop a
    first time over all customers to collect these values and a second time
    over that list to filter duplicates:
    As a matter of coincidence, I discovered today that neither frozenset
    nor set data types were exposed in Jinja templates (on Salt 2014.1.11).

    They would also be useful in boolean expressions such as :

         set(grains.get('roles', ())).isdisjoint(('prod', 'internal-prod',
         'leased'))

    which I tend to prefer over repeating three times grains.get('roles', ())

    --
    Georges Racinet
    Anybox SAS, http://anybox.fr
    Bureau: 09 72 39 50 97 / 09 72 39 13 06
    Portable: 06 51 32 07 27
    GPG: 0x33AB0A35, sur serveurs publics

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Pille at Oct 18, 2014 at 4:02 pm

    On 10/18/2014 03:00 PM, Georges Racinet wrote:
    As a matter of coincidence, I discovered today that neither frozenset
    nor set data types were exposed in Jinja templates (on Salt 2014.1.11).
    i've created a ticket: https://github.com/saltstack/salt/issues/16738

       pille

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Georges Racinet at Oct 18, 2014 at 4:17 pm

    On 10/18/2014 06:02 PM, pille wrote:
    On 10/18/2014 03:00 PM, Georges Racinet wrote:
    As a matter of coincidence, I discovered today that neither frozenset
    nor set data types were exposed in Jinja templates (on Salt 2014.1.11).
    i've created a ticket: https://github.com/saltstack/salt/issues/16738
    many thanks, I was wondering if I should directly make one :-)
    I'll look into it if I can find the time to, but that's not very likely
    in the short term.

    --
    Georges Racinet
    Anybox SAS, http://anybox.fr
    Bureau: 09 72 39 50 97 / 09 72 39 13 06
    Portable: 06 51 32 07 27
    GPG: 0x33AB0A35, sur serveurs publics

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupsalt-users @
postedOct 17, '14 at 2:37p
activeOct 18, '14 at 4:17p
posts6
users3

People

Translate

site design / logo © 2022 Grokbase