Extending salt to call a custom python function from within the yaml_jinja renderer

1,520 views
Skip to first unread message

Simon Inglis

unread,
Jul 25, 2012, 9:54:06 PM7/25/12
to salt-...@googlegroups.com
Hi all,

I would like to be able to call a custom python function from within my .sls file.

E.g.

special-state:
  file.managed:
    - name:  special_file_{{ my_hash_function(pillar['secret' ]) }}
    - source:  salt://special/file
    - ....


I have a suspicion that is will be trivial, but I can't quite get my head around how all the salt pieces fit together.  

Cheers,
Simon.

Thomas S Hatch

unread,
Jul 25, 2012, 9:56:36 PM7/25/12
to salt-...@googlegroups.com
It is trivial :)

Inside the jinja template you have access to a dict called salt, this dict has all of the functions that the salt command can run. If those available commands do not supply you with what you need, then you can add a custom module and call it

Simon Inglis

unread,
Jul 27, 2012, 12:46:04 AM7/27/12
to salt-...@googlegroups.com
Fantastic!  I thought it might be something like that.   Can you point me towards an example of usage; in particular an example using  function parameters?

Cheers,
Simon.


On Thursday, 26 July 2012 11:56:36 UTC+10, Thomas Hatch wrote:
It is trivial :)

Inside the jinja template you have access to a dict called salt, this dict has all of the functions that the salt command can run. If those available commands do not supply you with what you need, then you can add a custom module and call it

Thomas S Hatch

unread,
Jul 27, 2012, 1:39:45 AM7/27/12
to salt-...@googlegroups.com

Simon Inglis

unread,
Jul 27, 2012, 1:52:38 AM7/27/12
to salt-...@googlegroups.com
Thanks!


On Friday, 27 July 2012 15:39:45 UTC+10, Thomas Hatch wrote:
http://docs.saltstack.org/en/latest/topics/tutorials/states_pt3.html

should get your feet wet. 

Thomas S Hatch

unread,
Jul 27, 2012, 1:54:24 AM7/27/12
to salt-...@googlegroups.com
Sure thing, sorry I have been terse in my responses :)
Reply all
Reply to author
Forward
0 new messages