not all sls files are available on minion

24 views
Skip to first unread message

NdK ClanBO

unread,
Mar 4, 2024, 11:32:36 AMMar 4
to Salt-users
Hello all.

I'm having a problem.
I'd like to be able to automatically assisgn states based on the presence of pillars (or contents of pillars). For example, having a pillar that defines ceph configuration, I want to include "ceph-mon" if host is nominated in monitors section, "ceph-osd" if it's indicated as an osd and so on.

I created an "autorole" sls to automatically assign roles to minions based on pillars.
top.sls includes autoroles and autoroles/init.sls is:
-8<--
{% set SLS_ROOT = opts['cachedir']+'/files/'+saltenv+'/' %}

include:
  - autoroles.allhosts
  {%-for p in pillar %}
  {%- if salt['file.file_exists'](SLS_ROOT+'autoroles/'+p+'.sls') %}
  - autoroles.{{p}}
  {%- endif %}
  {%- endfor %}
-8<--

The problem is that when I apply histate to a minion, it does not find other sls files in autoroles/ even if they are present on the master. And actually the files are missing.
Seems Salt is "optimizing" by not copying sls files that are not referenced directly. Am I missing something?

Tks.

Diego

Phipps, Thomas

unread,
Mar 4, 2024, 12:34:35 PMMar 4
to salt-...@googlegroups.com

are you doing this through salt-ssh? if not file.file_exists only tests the file exists on the local filesystem not in the salt file system and no salt doesn’t transfer the whole filesystem to the minion. only the files that have been used. and the file hasn’t been used by that point. there is a reason it is called a cachedir

if you want to test is in the salt file system. us cp.list_master and check if the file is in the list returned to you.

something more along the lines of

also for concat in jinja use ~ not +, ~ will translate everything to str so that there is no type confusion in the system + does not.

{% set filename = ''autoroles" ~ p ~ ".sls"

{% if filename in salt["cp.list_master"](saltenv=saltenv,prefix=filename)  %}
stuff
{% endif %}

see https://docs.saltproject.io/en/latest/ref/modules/all/salt.modules.cp.html#salt.modules.cp.list_master


--
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/7e779704-a25d-46bd-a686-984a72bff122n%40googlegroups.com.

NdK ClanBO

unread,
Mar 5, 2024, 2:22:26 AMMar 5
to Salt-users
Tks a lot.
That's exactly what I needed and couldn't find.
Way better than the alternative (try to include every non-blacklisted pillar key).
Reply all
Reply to author
Forward
0 new messages