Saltstack set variables after a state

2.8k Views Asked by At

I have a question about SaltStack variables. I want to set a folder name, something like:

{% set exim4_folder = salt['cmd.run']('ls /tmp | grep exim4') %}

but the folder I am trying to get is not available till the state I ran before that assignment:

download_source_code:
  cmd.run:
    - cwd: /tmp
    - names:
      - apt-get -y source exim4
      - apt-get -y build-dep exim4

Is there a way to tell salt to run that assignment after I run "download_source_code"?

1

There are 1 best solutions below

0
On

The problem you're going to run into here is that all the jinja sections of your sls file will be evaluated before any of the yaml Salt states are evaluated.

So your 'ls /tmp | grep exim4' will always be executed before your download_source_code state is executed.