0

I'm trying to configure a state that will look at the home directories of the system, and iterate through them to check for specific files. To accomplish this I originally wrote up:

{% for userdir in salt['cmd.run']('ls /home').split('\n') %}

for my loop, and that works great. However, I want to make it easily configerable for alternate environments, so I had thought to store home directory locations inside a pillar, and changed the line to:

{% for userdir in salt['cmd.run']('ls pillar['home']').split('\n') %}

which gave a Jinja syntax error: expected token 'comma', got 'home'; i assume because of the double sets of embeded ''s

so I tried:

{% for userdir in salt['cmd.run']('ls pillar["home"]').split('\n') %}

which gave me: Rendering SLS failed: mapping values are not allowed here;

I've looked at a as many pillar loop situations as I can to try and find an example I can work off of, but it doesn't seem to exist.

is it possible to call pillar information from within the ls? Or is there a better way to accomplish this goal?

Any help would be appreciated.

Gravy
  • 770
  • 1
  • 5
  • 17

1 Answers1

4

You just have to do your mapping outside the string: {% for userdir in salt['cmd.run']('ls '+pillar['home']).split('\n') %}

Christophe Drevet
  • 1,962
  • 2
  • 17
  • 25