I have a Salt state which checks multiple files exist on our webservers, we have 4 webservers and 2 environments so a combined total of 8. This state is applied to all by using a grain 'webserver'.
As the webservers are different (same underlying back end, different directory/file names) I have implemented an if statement which makes use of the inbuilt grains functionality 'host'.
{% if grains['host'] == 'dev-server1', 'test-server1' %}
dart-index.html:
file.exists:
- name: /opt/tomcat/webapps/example1/index.html
{% endif %}
When applying my state to all 'webserver' minions, this worked as expected. It checked for the above file on the target minions (dev-server1/test-server1) and ignored the others. However I have since added another if statement below this for dev-server2/test-server2:
{% if grains['host'] == 'dev-server2', 'test-server2' %}
tees-index.html:
file.exists:
- name: /opt/tomcat/webapps/example2/index.html
{% endif %}
Now whenever I run the state against the minions it fails as it attempts to check whether both of the above files exist across all minions (which of course won't exist).
So, is it possible to use multiple if statements in a state? Alternatively is there another method in which I could achieve the same goal? I would like to identify multiple files with a specific directory/file name in each type of webserver.