Running local (and not remote) file through Jinja

19 views
Skip to first unread message

Marc Baudoin

unread,
Jun 29, 2015, 12:03:33 PM6/29/15
to salt-...@googlegroups.com
Hi,

I have been searching if it's possible with no luck whatsoever.

I have a bunch of files in a git repository I transfer them from master to minions using file.recurse.  Those files are actually Jinja templates I have to substitute in each directory one at a time. So, for now, I have two Jinja loops surrounding the file.recurse transfer:

{% for ... %}
{% for ... %}
file.recurse a part of the repository
{% endfor %}
{% endfor %}

This is working fine but I believe performance would be better if I could do the file.recurse transfer once and then the Jinja templating on local files:

file.recurse the whole repository
{% for ... %}
{% for ... %}
Jinja operation on local files
{% endfor %}
{% endfor %}

Is it possible?  How?

Marc Baudoin

unread,
Jun 30, 2015, 5:14:43 AM6/30/15
to salt-...@googlegroups.com
[ Replying to myself ]

This is not exactly what I wanted but it'll do the trick, I'll be using file.blockreplace somewhat like that:

{% set var1 = value1 %}
{% set var2 = value2 %}

test:
  file.blockreplace:
    - name: /path/to/file
    - marker_start: '# BEGIN SALT BLOCK'
    - content:      'key1: {{ var1 }}'
    - content:      'key2: {{ var2 }}'
    - marker_end:   '# END SALT BLOCK'
    - backup: False

Ethan Erchinger

unread,
Jul 2, 2015, 2:29:52 PM7/2/15
to salt-...@googlegroups.com
Does setting "template: jinja" on the file.recurse state not work?
Reply all
Reply to author
Forward
0 new messages