Slatstack file-source with a grains inside?

10 views
Skip to first unread message

Rainer Krienke

unread,
Jun 14, 2018, 10:36:59 AM6/14/18
to Salt-users
Hello,

I am coming from puppet and am now trying to learning saltstack. I would like to find a "best practice way2 to install different versions of the same config file (eg /etc/ssh/sshd_config) for say different linux distros (Ubuntu, SLES, ...). So after all I would like to have a grain like os_family or any other that makes sense to be part of a source path like shown below:

openssh-server.sls:

 openssh_server_conf:
  file.managed:
    - name: /etc/ssh/sshd_config,
    - source: {{ salt['pillar.get']('openssh_server:lookup:config:grains["osfullname"]') }}
    - source: {{ salt['pillar.get']('openssh_server:lookup:config:default') }}


with pillar: openssh_server.sls:

openssh-server:
  lookup:
    config:
      Ubuntu:salt://openssh-server/files/Ubuntu/etc/ssh/sshd_config
      default: salt://openssh-server/files/etc/ssh/sshd_config


However this results in an empty ssh file beeing installed. It seems that the grain osfullname is not correctly evaluated.
so something does not work as I expected. 

If I add a single source path using:

- source: salt://openssh-server/files/{{ grains['osfullname'] }}/etc/ssh/sshd_config

it works as expected, but it would be nice to have the openssh-server -pillar as a additional abstraction layer.

Any idea how to get this working?

Thanks a lot
Rainer

Dafydd Jones (techneg.it)

unread,
Jun 14, 2018, 5:59:47 PM6/14/18
to salt-...@googlegroups.com
Hi,

you're passing a string variable to the first pillar.get, so you need to construct that string using the grain value using Jinja string concatenation:

- source: {{ salt['pillar.get']('openssh_server:lookup:config:' ~ grains["osfullname"]) }}

Bear in mind also that in the first line of the pillar file you need to replace the hyphen with an underscore to match the name of the pillar item specified in the pillar.get line.

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/5a089eeb-dbaa-4564-a274-2b114c4639c1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rainer Krienke

unread,
Jun 15, 2018, 7:08:57 AM6/15/18
to Salt-users
Hello,

thanks for your answer now it works as expected.

Have a nice day
Rainer
Dafydd

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