Parameterising salt sls files

77 views
Skip to first unread message

jm

unread,
Aug 10, 2017, 9:42:03 PM8/10/17
to Salt-users
I've found how to pass parameters into sls files by first creating a
file with

#!stateconf yaml . jinja

.params:
stateconf.set:
package: default
start_cmd: default
conf_file: default
conf_tmpl: default

then in the sls file your calling it from,

include:
.firstfile

extends:
.firstfile:
stateconf.set:
- package: apkg
- start_cmd: /usr/bin/runit

This limits the re-use to one. It would be better to be able to do,

setup-rsyslog:
state.sls:
- name: firstfile
- params:
- package: rsyslog
- start_cmd: /sbin/rsyslogd -i /var/run/syslogd.pid -c 5 -n
- conf_file: /etc/rsyslog.conf
- conf_tmpl: salt://path/files/rsyslog.conf

setup-cron:
state.sls:
- name: firstfile
- params:
- package: cronie
- start_cmd: /usr/sbin/crond -n

Not only is it clearer, this would allow the use of the sls file
multiple times and to be able to treat it in the same manner as a state.
is there a way to do this?


Jeff.




Adam Mendlik

unread,
Aug 11, 2017, 12:58:52 PM8/11/17
to Salt-users
It is possible to include SLS files and pass parameters into the namespace of the included file like this:

{% with
  package="rsyslog",
  start_cmd="/sbin/rsyslogd -i /var/run/syslogd.pid -c 5 -n",
  conf_file="/etc/rsyslog.conf",
  conf_tmpl="salt://path/files/rsyslog.conf"
-%}
{% include "firstfile.sls" -%}
{% endwith -%}

Each of those four variables will be present in the namespace when firstfile.sls is rendered.

jm

unread,
Aug 13, 2017, 8:09:07 PM8/13/17
to salt-...@googlegroups.com
Can I do that, say, five times in the same file or is it can it only be used once?

Jeff.
--
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+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/salt-users/65904983-aa48-4326-9a40-c1fd97652e59%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Adam Mendlik

unread,
Aug 14, 2017, 6:56:57 PM8/14/17
to Salt-users
You can include it multiple times in the same file, or from different files. The only trick is that the state ID must still be globally unique. That can be achieved in various ways, but typically you would include one or more of the passed variables in the state ID.

jm

unread,
Aug 16, 2017, 11:27:21 PM8/16/17
to salt-...@googlegroups.com
Thanks. I'll give that a go.

Jeff.
Reply all
Reply to author
Forward
0 new messages