I have a saltstack script where I add 2 files into /etc/apt/sources.list.d/ using file.managed followed by a for loop like below
{% for repo in salt['file.find']('/etc/apt/sources.list.d/',name='*list') -%}
The for loop is not picking up the two newly added files in prior steps. Anyone know how to force saltstack to evaluate the for loop after the files are written?
This might be because jinja is rendered before running the formula. Essentially it evaluates files in /etc/apt/sources.list.d/ first, “unwraps” your state by writing a set of states for each iteration of the loop, and only then sends it to salt to execute.
If you want to capture the change of files with jinja, you need to run a separate state file. Inclusion doesn’t work, because it is rendered before execution too.
Solene is right. Writing a script is a better option.