Variable containing filename in file.managed state file ?

68 views
Skip to first unread message

Rainer Krienke

unread,
Jun 21, 2018, 5:09:41 AM6/21/18
to Salt-users
Hello,

I just started with salt and I often use several source paths for a certain file so taht I can have different versions of the same file for different os variants or os releases.

A state file for a file /root/bin/myfile  then might look like this:

/root/bin/myscript:
  file.managed:
  -source:
      - salt://packageupdates/files/{{ grains['host'] }}/root/bin/myscript
      - salt://packageupdates/files/{{ grains['os_family'] }}/{{ grains['osfullname'] }}/{{ grains['osrelease'] }}/root/bin/myscript
      - salt://packageupdates/files/{{ grains['os_family'] }}/{{ grains['osfullname'] }}/root/bin/myscript
      - salt://packageupdates/files/root/bin/myscript

Now I would like to modify the last part of source path by inserting a variable that
contains the name of the state which is usually the filepath and name. This way  I could avoid the need to write the filename and path at each end of the source line:

     - salt://packageupdates/files/{{ grains['os_family'] }}/{{ grains['osfullname'] }}/{{ grains['osrelease'] }}/{{ statename }}

The question is, is there a variable for the filename (here: /root/bin/myscript) I can use as a reference like indicated by {{ statename }} from above? Is there somewhere a list of similar variables documented?

Thanks a lot
Rainer

Dafydd Jones (techneg.it)

unread,
Jun 21, 2018, 8:03:28 AM6/21/18
to salt-...@googlegroups.com
Hi,

there is not a variable for the sls id, as far as I'm aware, although there are some built-in template variables available.

Of course, you could set your own Jinja variable containing the value you need, and use it multiple times as needed.

HTH,
Dafydd

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/salt-users/8fc66da1-03de-4790-b059-13441f4dea4c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rainer Krienke

unread,
Jun 21, 2018, 11:17:30 AM6/21/18
to Salt-users
Good idea. It will make life easier...

Thank you very much
Rainer
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages