Created
April 22, 2015 15:21
-
-
Save borutmrak/333049c7e43cd7d7aab8 to your computer and use it in GitHub Desktop.
asterisk pillar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
asterisk: | |
sip: | |
users: | |
'00_tpl_grandstream-phone': | |
opts: | |
type: "friend" | |
context: "from-local" | |
host: "dynamic" | |
nat: "no" | |
dtmfmode: "rfc2833" | |
disallow: "all" | |
allow: "g722,alaw,ulaw" | |
parent: | |
"!" | |
dids: [] | |
localexts: [] | |
'800': | |
opts: | |
secret: xxxx | |
call-limit: 1 | |
parent: | |
00_tpl_grandstream-phone | |
"802": | |
opts: | |
secret: xxxx | |
parent: | |
00_tpl_grandstream-phone |
How about this? Is there a way to simplify:
{%- for user, args in salt['pillar.get']('asterisk:sip:users') | dictsort %}
[{{ user }}]({{ args['parent'] }})
{%- if 'disallow' in args['opts'].keys() %}
disallow={{ args['opts']['disallow'] }}
allow={{ args['opts']['allow'] }}
{%- do args['opts'].pop('allow', None) -%}
{%- do args['opts'].pop('disallow', None) -%}
{%- endif %}
{%- for opt, optval in args['opts'].items() %}
{{ opt }}={{ optval }}
{%- endfor %}
{% endfor %}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm at a loss how to use this...
My template looks like this:
{% set sip_config = pillar.get('asterisk', {})['sip'] %}
{%- if 'users' in sip_config.keys() %}
{% for user, args in sip_config['users'].items() -%}
{%- if 'localexts' in args.keys() -%}
{%- set exts = args['localexts'] -%}
{%- else -%}
{%- set exts = [ user ] -%}
{%- endif -%}
{%- for ext in exts %}
exten => {{ ext }},1,Dial(SIP/{{ user }}/{{ ext }},,wWxXtT)
{%- endfor %}
{% endfor %}
{% endif %}
supposedly it should work better with:
sip_config = salt[pillar.get]('asterisk:sip', {}).items()
or
sip_config = pillar.get('asterisk', {'sip':{}})['sip']
The first one doesn't work, it seems I get a different object and other stuff in the template fails. Is there a good doc accessing data in pillars (when one needs .items() etc.) other than http://docs.saltstack.com/en/latest/topics/tutorials/pillar.html? What is the difference between salt'pillar.get' and pillar.get() ?