FAQ
Hi all
I am using master less salt version 2014.1.2

I have a custom module which returns a dict;

{u'A': [u'i-as', u'i-sc', u'rtb-be', 'east'], u'B': [u'i-c9', u'i-29',
u'rtb-dd', 'east']}

I want to use this dict to populate a template file.

Template:

{
     "checks": {
         "expiring_domains": {
             "command": "/etc/plugins/check.py
             "interval": 300,
             "subscribers": [ "master" ],
             "occurrences": 3
         }
     },
     {% for k in template_vars.keys() %}
     {{ k }}: {
         "n1": {{ k[0] }},
         "n2": {{ k[1] }},
         "rt": {{ k[2] }},
         "region": {{ k[3] }},
     }
     {% endfor %}
}

This is how I am managing the file:

nat_config:
     file.managed:
       - name: name
       - source: salt://source
       - template: jinja
       - defaults:
         template_vars:{{ salt['tracker.function_name'] }}

Since I was not able to get this going (minion was saying "Jinja variable
'unicode object' has no attribute 'keys' ") I printed out template_vars in
the template file and I got this:
template_vars:<function function-name@0x40bf230>

Can some one please help me out here. I am not sure why template_vars is
not a dict.

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

Search Discussions

  • Seth House at Aug 14, 2014 at 2:56 am

    On Aug 13, 2014 9:37 PM, "apz" wrote:
    Templars
    You're grabbing the function object but haven't called it yet. Try adding
    parens at the end:

    template_vars:{{ salt['tracker.function_name']() }}

    --
    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.
  • Apz at Aug 14, 2014 at 6:53 am
    Thanks a lot Seth for this help, it worked.
    On Wednesday, August 13, 2014 6:37:40 PM UTC-7, apz wrote:

    Hi all
    I am using master less salt version 2014.1.2

    I have a custom module which returns a dict;

    {u'A': [u'i-as', u'i-sc', u'rtb-be', 'east'], u'B': [u'i-c9', u'i-29',
    u'rtb-dd', 'east']}

    I want to use this dict to populate a template file.

    Template:

    {
    "checks": {
    "expiring_domains": {
    "command": "/etc/plugins/check.py
    "interval": 300,
    "subscribers": [ "master" ],
    "occurrences": 3
    }
    },
    {% for k in template_vars.keys() %}
    {{ k }}: {
    "n1": {{ k[0] }},
    "n2": {{ k[1] }},
    "rt": {{ k[2] }},
    "region": {{ k[3] }},
    }
    {% endfor %}
    }

    This is how I am managing the file:

    nat_config:
    file.managed:
    - name: name
    - source: salt://source
    - template: jinja
    - defaults:
    template_vars:{{ salt['tracker.function_name'] }}

    Since I was not able to get this going (minion was saying "Jinja variable
    'unicode object' has no attribute 'keys' ") I printed out template_vars in
    the template file and I got this:
    template_vars:<function function-name@0x40bf230>

    Can some one please help me out here. I am not sure why template_vars is
    not a dict.

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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupsalt-users @
postedAug 14, '14 at 1:37a
activeAug 14, '14 at 6:53a
posts3
users2

2 users in discussion

Apz: 2 posts Seth House: 1 post

People

Translate

site design / logo © 2022 Grokbase