<p>I have found the answer to my own question after some more investigation.</p>

<p>The reason the state was skipping the contents of my if statement was because the hostname of the server was in lower-case (god knows why). Therefore the in-built salt grains.item host which is called upon didn't recognise the server I was specifying.</p>

CC BY-SA 3.0
2017-09-22T11:34:57.693Z
2017-09-22T11:34:57.693Z
jto
<p>I recently asked a question here: <a href="https://devops.stackexchange.com/questions/2058/is-it-possible-to-use-multiple-if-statements-in-a-salt-state">Is it possible to use multiple if statements in a salt state?</a></p>

<p>Thanks to the answer I have managed to update my state to only check specific files exist on specific servers defined in the if statement. However, there's an issue with one server, the state runs fine against it and doesn't error, however it is only checking 32 files on TEST-SERVER-04, whereas it's 'DEV' counterpart (defined in the same if statement) has all 50 files checked.</p>

<p>For the life of me I can't work out why! If I try running the state directly against the server (i.e. salt 'test-server-04' state.sls filecheck') it still does the same thing! I have checked my syntax repeatedly, checked for white lines etc but to no avail! I'm sure somebody will be able to point out what I have done wrong here!</p>

<p>Below is a snippet of the affected code:</p>

<pre><code>######################################################################################################################## // THIS STATE IS USED TO CHECK THAT ALL MINIONS (JL/TL LINUX SERVERS) IDENTIFIED AS 'WEBSERVER' HAVE THE CORRECT CONFIGURATION FILES AND SERVICES IN PLACE.
#######################################################################################################################

checkservices.sh:
  file.exists:
    - name: /opt/checkservices.sh

####################################################################################################################
# // THIS SECTION CHECKS THE CONFIG FILES IN /OPT/TOMCAT/CONF EXIST
####################################################################################################################

catalina.properties:
  file.exists:
    - name: /opt/tomcat/conf/catalina.properties

logging.properties:
  file.exists:
    - name: /opt/tomcat/conf/logging.properties

web.xml:
  file.exists:
    - name: /opt/tomcat/conf/web.xml

tomcat-users.xml:
  file.exists:
   - name: /opt/tomcat/conf/tomcat-users.xml

server.xml:
  file.exists:
    - name: /opt/tomcat/conf/server.xml

context.xml:
  file.exists:
    - name: /opt/tomcat/conf/context.xml

catalina.policy:
  file.exists:
    - name: /opt/tomcat/conf/catalina.policy

####################################################################################################################
# // THIS SECTION CHECKS THE CORRECT JHC SCRIPTS ARE IN /OPT/TOMCAT/BIN (JHC JETS ADMINISTRATION SCRIPTS)
####################################################################################################################

jhcshutdown.sh:
  file.exists:
    - name: /opt/tomcat/bin/jhcshutdown.sh

jhcstartup.sh:
  file.exists:
    - name: /opt/tomcat/bin/jhcstartup.sh

jhc-tomcat-util.sh:
  file.exists:
    - name: /opt/tomcat/bin/jhc-tomcat-util.sh

jhc-tomcat-before-startup.sh:
  file.exists:
    - name: /opt/tomcat/bin/jhc-tomcat-before-startup.sh

jhc-tomcat-after-startup.sh:
  file.exists:
    - name: /opt/tomcat/bin/jhc-tomcat-after-startup.sh

jhc-tomcat-after-shutdown.sh:
  file.exists:
    - name: /opt/tomcat/bin/jhc-tomcat-after-shutdown.sh

shutdown.sh:
  file.exists:
    - name: /opt/tomcat/bin/shutdown.sh

startup.sh:
  file.exists:
    - name: /opt/tomcat/bin/startup.sh

version.sh:
  file.exists:
    - name: /opt/tomcat/bin/version.sh

tool-wrapper.sh:
  file.exists:
    - name: /opt/tomcat/bin/tool-wrapper.sh

setclasspath.sh:
  file.exists:
    - name: /opt/tomcat/bin/setclasspath.sh

digest.sh:
  file.exists:
    - name: /opt/tomcat/bin/digest.sh

daemon.sh:
  file.exists:
    - name: /opt/tomcat/bin/daemon.sh

configtest.sh:
  file.exists:
    - name: /opt/tomcat/bin/configtest.sh

catalina.sh:
  file.exists:
    - name: /opt/tomcat/bin/catalina.sh

bootstrap.jar:
  file.exists:
    - name: /opt/tomcat/bin/bootstrap.jar

#####################################################################################################################                      THIS SECTION CHECKS THAT THE TOMCAT LOGS ARE PRESENT IN /OPT/TOMCAT/LOGS/
####################################################################################################################

jhc.jets.log:
  file.exists:
    - name: /opt/tomcat/logs/jhc.jets.log

catalina.out:
  file.exists:
    - name: /opt/tomcat/logs/catalina.out

{% if grains['host'] in ['BCA-AJT-TC-04', 'BCA-AJU-TC-04', 'BCA-AJT-TC-05', 'BCA-AJU-TC-05', 'BCA-AJT-TC-07', 'BCA-AJU-TC-07'] %}

demo-admin.log:
  file.exists:
    - name: /opt/tomcat/logs/demo-admin.log

{% endif %}

minion.log:
  file.exists:
    - name: /var/log/salt/minion

lynis.log:
  file.exists:
    - name: /var/log/lynis.log

#####################################################################################################################                       TEES FINANCIAL SPECIFIC CONFIG
####################################################################################################################

{% if grains['host'] in ['BCA-AJU-TC-04', 'BCA-AJT-TC-04'] %}

tees-pom.properties:
  file.exists:
    - name: /opt/tomcat/webapps/website1/META-INF/maven/jhc.client.F63.web.figaroweb/ajb-2/pom.properties

tees-pom.xml:
  file.exists:
    - name: /opt/tomcat/webapps/website1/META-INF/maven/jhc.client.F63.web.figaroweb/ajb-2/pom.xml

tees-web.xml:
  file.exists:
    - name: /opt/tomcat/webapps/website1/WEB-INF/web.xml

tees-jets-jca-client.xml:
  file.exists:
    - name: /opt/tomcat/webapps/website1/WEB-INF/classes/conf/jets-jca-client.xml

tees-index.html:
  file.exists:
    - name: /opt/tomcat/webapps/website1/index.html

tees-logo.png:
  file.exists:
    - name: /opt/tomcat/webapps/website1/statics/images/logo.png

tees-logo_website1.png:
  file.exists:
    - name: /opt/tomcat/webapps/website1/statics/images/logo_website1.png

tees-notfound.gif:
  file.exists:
    - name: /opt/tomcat/webapps/website1/statics/images/notfound.gif

tees-sessionKeepAliveImage.png:
  file.exists:
    - name: /opt/tomcat/webapps/website1/images/sessionKeepAliveImage.png

tees-site.properties:
  file.exists:
    - name: /opt/jhc/ajb-2/config/site.properties

tees.properties:
  file.exists:
    - name: /opt/jhc/ajb-2/config/ajb-2.properties

tees-common-site.properties:
  file.exists:
    - name: /opt/jhc/ajb-2/config/common-site.properties

tees-environment.properties:
  file.exists:
    - name: /opt/jhc/ajb-2/config/environment.properties

tees-Admin.properties:
  file.exists:
    - name: /opt/jhc/ajb-2/config/Admin.properties

tees-log4j-Client.properties:
  file.exists:
    - name: /opt/jhc/ajb-2/config/log4j-Client.properties

tees-log4j-Admin.properties:
  file.exists:
    - name: /opt/jhc/ajb-2/config/log4j-Admin.properties

tees-website1.properties:
  file.exists:
    - name: /opt/jhc/ajb-2/config/website1.properties

tees-ehcache.xml:
  file.exists:
    - name: /opt/jhc/ajb-2/config/ehcache.xml

{% endif %}

#####################################################################################################################                                           DART CAPITAL SPECIFIC CONFIG
####################################################################################################################

{% if grains['host'] in ['BCA-AJT-TC-03', 'BCA-AJU-TC-03'] %}

dart-pom.properties:
  file.exists:
    - name: /opt/tomcat/webapps/website2/META-INF/maven/jhc.client.F63.web.figaroweb/website2/pom.properties

dart-pom.xml:
  file.exists:
    - name: /opt/tomcat/webapps/website2/META-INF/maven/jhc.client.F63.web.figaroweb/website2/pom.xml

dart-index.html:
  file.exists:
    - name: /opt/tomcat/webapps/website2/index.html

dart-logo.png:
  file.exists:
    - name: /opt/tomcat/webapps/website2/statics/images/logo.png

dart-notfound.gif:
  file.exists:
    - name: /opt/tomcat/webapps/website2/statics/images/notfound.gif

dart-sessionKeepAlive.png:
  file.exists:
    - name: /opt/tomcat/webapps/website2/images/sessionKeepAliveImage.png

dart.log:
  file.exists:
    - name: /opt/tomcat/logs/dart.log

dart-site.properties:
  file.exists:
    - name: /opt/jhc/website2/config/site.properties

dart-common-site.properties:
  file.exists:
    - name: /opt/jhc/website2/config/common-site.properties

dart-environment.properties:
  file.exists:
    - name: /opt/jhc/website2/config/environment.properties

dart-Admin.properties:
  file.exists:
   - name: /opt/jhc/website2/config/Admin.properties

dart-Client.properties:
  file.exists:
    - name: /opt/jhc/website2/config/Client.properties

dart-log4j-Client.properties:
  file.exists:
    - name: /opt/jhc/website2/config/log4j-Client.properties

dart-log4j-Admin.properties:
  file.exists:
    - name: /opt/jhc/website2/config/log4j-Admin.properties

dart-ehcache.xml:
  file.exists:
    - name: /opt/jhc/website2/config/ehcache.xml

dart-website2-client.log:
  file.exists:
    - name: /opt/tomcat/logs/website2-client.log

dart-website2-admin.log:
  file.exists:
    - name: /opt/tomcat/logs/website2-admin.log

{% endif %}

#####################################################################################################################                                           website3 SPECIFIC CONFIG
####################################################################################################################

{% if grains['host'] in ['BCA-AJT-TC-07', 'BCA-AJU-TC-07'] %}

website3-pom.xml:
  file.exists:
    - name: /opt/tomcat/webapps/website3/META-INF/maven/jhc.client.F63.web.figaroweb/website3/pom.xml

website3-pom.properties:
  file.exists:
    - name: /opt/tomcat/webapps/website3/META-INF/maven/jhc.client.F63.web.figaroweb/website3/pom.properties

website3-index.html:
  file.exists:
    - name: /opt/tomcat/webapps/website3/index.html

website3-logo.png:
  file.exists:
    - name: /opt/tomcat/webapps/website3/statics/images/logo.png

website3-notfound.gif:
  file.exists:
    - name: /opt/tomcat/webapps/website3/statics/images/notfound.gif

website3-sessionKeepAlive.png:
  file.exists:
    - name: /opt/tomcat/webapps/website3/images/sessionKeepAliveImage.png

website3-site.properties:
  file.exists:
    - name: /opt/jhc/website3/config/site.properties

website3.properties:
  file.exists:
    - name: /opt/jhc/website3/config/website3.properties

website3-common-site.properties:
  file.exists:
    - name: /opt/jhc/website3/config/common-site.properties

website3-environment.properties:
  file.exists:
    - name: /opt/jhc/website3/config/environment.properties

website3-Admin.properties:
  file.exists:
   - name: /opt/jhc/website3/config/Admin.properties

website3-Client.properties:
  file.exists:
    - name: /opt/jhc/website3/config/Client.properties

website3-log4j-Client.properties:
  file.exists:
    - name: /opt/jhc/website3/config/log4j-Client.properties

website3-log4j-Admin.properties:
  file.exists:
    - name: /opt/jhc/website3/config/log4j-Admin.properties

website3-ehcache.xml:
  file.exists:
    - name: /opt/jhc/website3/config/ehcache.xml

website3-website3.properties:
  file.exists:
    - name: /opt/jhc/website3/config/website3.properties


{% endif %}

#####################################################################################################################                       MONEY MATTERS SPECIFIC CONFIG
####################################################################################################################

{% if grains['host'] in ['BCA-AJT-TC-05', 'BCA-AJU-TC-05'] %}

website4-pom.xml:
  file.exists:
    - name: /opt/tomcat/webapps/website4/META-INF/maven/jhc.client.F63.web.figaroweb/ajb-1/pom.xml

website4-pom.properties:
  file.exists:
    - name: /opt/tomcat/webapps/website4/META-INF/maven/jhc.client.F63.web.figaroweb/ajb-1/pom.properties

website4-index.html:
  file.exists:
    - name: /opt/tomcat/webapps/website4/index.html

website4-logo.png:
  file.exists:
    - name: /opt/tomcat/webapps/website4/statics/images/logo.png

website4-notfound.gif:
  file.exists:
    - name: /opt/tomcat/webapps/website4/statics/images/notfound.gif

website4-sessionKeepAlive.png:
  file.exists:
    - name: /opt/tomcat/webapps/website4/images/sessionKeepAliveImage.png

website4-site.properties:
  file.exists:
    - name: /opt/jhc/ajb-1/config/site.properties

website4.properties:
  file.exists:
    - name: /opt/jhc/ajb-1/config/ajb-1.properties

website4-common-site.properties:
  file.exists:
    - name: /opt/jhc/ajb-1/config/common-site.properties

website4-environment.properties:
  file.exists:
    - name: /opt/jhc/ajb-1/config/environment.properties

website4-Admin.properties:
  file.exists:
   - name: /opt/jhc/ajb-1/config/Admin.properties

website4-log4j-Client.properties:
  file.exists:
    - name: /opt/jhc/ajb-1/config/log4j-Client.properties

website4-log4j-Admin.properties:
  file.exists:
    - name: /opt/jhc/ajb-1/config/log4j-Admin.properties

website4-ehcache.xml:
  file.exists:
    - name: /opt/jhc/ajb-1/config/ehcache.xml

website4-website3.properties:
  file.exists:
    - name: /opt/jhc/ajb-1/config/ajb-1.properties

{% endif %}

##################################################################################################################### THIS SECTION CHECKS THAT SERVICES ARE RUNNING ON EACH TOMCAT SERVER
####################################################################################################################

{% if grains['host'] in ['BCA-AJT-TC-04', 'BCA-AJU-TC-04', 'BCA-AJT-TC-07', 'BCA-AJU-TC-07'] %}

httpd:
  service.running:
    - name: httpd
    - enable: True

httpd.conf:
  file.exists:
    - name: /etc/httpd/conf/httpd.conf

php.conf:
  file.exists:
    - name: /etc/httpd/conf.d/php.conf

{% endif %}

rsyslog:
  service.running:
    - name: rsyslog
    - enable: True

salt-minion:
  service.running:
    - name: salt-minion
    - enable: True

sshd:
  service.running:
    - name: sshd
    - enable: True

ntpd:
  service.running:
    - name: ntpd
    - enable: True

check_jets:
  cmd.run:
    - name: ps aux | grep 'org.apache.catalina.startup.Bootstrap start' | grep -v grep
</code></pre>

<p>It may also be worth mentioning that I have used the above method in multiple areas across my state for the same purpose, yet targeting dev/test-server-01, 02, 03 etc without problems. It's specifically a problem with this section of code as other sections which target TEST-SERVER-04 in the state work fine (as I mentioned it runs 32/50)</p>

CC BY-SA 3.0
2017-09-22T09:31:15.133Z
I think you should share your whole file, as is it would be guessing to find what could be wrong somewhere. Sometimes the inner snippet not running is not the root cause, maybe you have another if statement not closed which prevent a block of the file to be evaluated.
Tensibai
CC BY-SA 3.0
2017-09-22T09:40:20.487Z
@Tensibai Do you have any recommendations as to where I could upload the file? It is large (not in size) and would be very time consuming to edit on stack exchange to make it readable.
jto
CC BY-SA 3.0
2017-09-22T10:06:50.823Z
Why that ? copy paste it, select the code and press CTRL+K to add the 4 spaces or click on the `{}` button. Unless it would extend the question up to 30 000 chars, there's no reason to not paste it here. If that's not a viable solution for you, maybe https://gist.github.com
Tensibai
CC BY-SA 3.0
2017-09-22T10:36:47.787Z
@Tensibai - I didn't know that was a possibility, thanks for that!
jto
CC BY-SA 3.0
2017-09-22T11:37:02.057Z
Glad it helped and you found the problem ;)
Tensibai
<salt><jinja><yaml>
Salt State is running against all servers except one, why?
jto
# Salt State is running against all servers except one, why?

(Asked by: username_0 on 2017-09-22)

I recently asked a question here: Is it possible to use multiple if statements in a salt state?
Thanks to the answer I have managed to update my state to only check specific files exist on specific servers defined in the if statement. However, there's an issue with one server, the state runs fine against it and doesn't error, however it is only checking 32 files on TEST-SERVER-04, whereas it's 'DEV' counterpart (defined in the same if statement) has all 50 files checked.
For the life of me I can't work out why! If I try running the state directly against the server (i.e. salt 'test-server-04' state.sls filecheck') it still does the same thing! I have checked my syntax repeatedly, checked for white lines etc but to no avail! I'm sure somebody will be able to point out what I have done wrong here!
Below is a snippet of the affected code:
######################################################################################################################## // THIS STATE IS USED TO CHECK THAT ALL MINIONS (JL/TL LINUX SERVERS) IDENTIFIED AS 'WEBSERVER' HAVE THE CORRECT CONFIGURATION FILES AND SERVICES IN PLACE.
#######################################################################################################################

checkservices.sh:
  file.exists:
    - name: /opt/checkservices.sh

####################################################################################################################
# // THIS SECTION CHECKS THE CONFIG FILES IN /OPT/TOMCAT/CONF EXIST
####################################################################################################################

catalina.properties:
  file.exists:
    - name: /opt/tomcat/conf/catalina.properties

logging.properties:
  file.exists:
    - name: /opt/tomcat/conf/logging.properties

web.xml:
  file.exists:
    - name: /opt/tomcat/conf/web.xml

tomcat-users.xml:
  file.exists:
   - name: /opt/tomcat/conf/tomcat-users.xml

server.xml:
  file.exists:
    - name: /opt/tomcat/conf/server.xml

context.xml:
  file.exists:
    - name: /opt/tomcat/conf/context.xml

catalina.policy:
  file.exists:
    - name: /opt/tomcat/conf/catalina.policy

####################################################################################################################
# // THIS SECTION CHECKS THE CORRECT JHC SCRIPTS ARE IN /OPT/TOMCAT/BIN (JHC JETS ADMINISTRATION SCRIPTS)
####################################################################################################################

jhcshutdown.sh:
  file.exists:
    - name: /opt/tomcat/bin/jhcshutdown.sh

jhcstartup.sh:
  file.exists:
    - name: /opt/tomcat/bin/jhcstartup.sh

jhc-tomcat-util.sh:
  file.exists:
    - name: /opt/tomcat/bin/jhc-tomcat-util.sh

jhc-tomcat-before-startup.sh:
  file.exists:
    - name: /opt/tomcat/bin/jhc-tomcat-before-startup.sh

jhc-tomcat-after-startup.sh:
  file.exists:
    - name: /opt/tomcat/bin/jhc-tomcat-after-startup.sh

jhc-tomcat-after-shutdown.sh:
  file.exists:
    - name: /opt/tomcat/bin/jhc-tomcat-after-shutdown.sh

shutdown.sh:
  file.exists:
    - name: /opt/tomcat/bin/shutdown.sh

startup.sh:
  file.exists:
    - name: /opt/tomcat/bin/startup.sh

version.sh:
  file.exists:
    - name: /opt/tomcat/bin/version.sh

tool-wrapper.sh:
  file.exists:
    - name: /opt/tomcat/bin/tool-wrapper.sh

setclasspath.sh:
  file.exists:
    - name: /opt/tomcat/bin/setclasspath.sh

digest.sh:
  file.exists:
    - name: /opt/tomcat/bin/digest.sh

daemon.sh:
  file.exists:
    - name: /opt/tomcat/bin/daemon.sh

configtest.sh:
  file.exists:
    - name: /opt/tomcat/bin/configtest.sh

catalina.sh:
  file.exists:
    - name: /opt/tomcat/bin/catalina.sh

bootstrap.jar:
  file.exists:
    - name: /opt/tomcat/bin/bootstrap.jar

#####################################################################################################################                      THIS SECTION CHECKS THAT THE TOMCAT LOGS ARE PRESENT IN /OPT/TOMCAT/LOGS/
####################################################################################################################

jhc.jets.log:
  file.exists:
    - name: /opt/tomcat/logs/jhc.jets.log

catalina.out:
  file.exists:
    - name: /opt/tomcat/logs/catalina.out

{% if grains['host'] in ['BCA-AJT-TC-04', 'BCA-AJU-TC-04', 'BCA-AJT-TC-05', 'BCA-AJU-TC-05', 'BCA-AJT-TC-07', 'BCA-AJU-TC-07'] %}

demo-admin.log:
  file.exists:
    - name: /opt/tomcat/logs/demo-admin.log

{% endif %}

minion.log:
  file.exists:
    - name: /var/log/salt/minion

lynis.log:
  file.exists:
    - name: /var/log/lynis.log

#####################################################################################################################                       TEES FINANCIAL SPECIFIC CONFIG
####################################################################################################################

{% if grains['host'] in ['BCA-AJU-TC-04', 'BCA-AJT-TC-04'] %}

tees-pom.properties:
  file.exists:
    - name: /opt/tomcat/webapps/website1/META-INF/maven/jhc.client.F63.web.figaroweb/ajb-2/pom.properties

tees-pom.xml:
  file.exists:
    - name: /opt/tomcat/webapps/website1/META-INF/maven/jhc.client.F63.web.figaroweb/ajb-2/pom.xml

tees-web.xml:
  file.exists:
    - name: /opt/tomcat/webapps/website1/WEB-INF/web.xml

tees-jets-jca-client.xml:
  file.exists:
    - name: /opt/tomcat/webapps/website1/WEB-INF/classes/conf/jets-jca-client.xml

tees-index.html:
  file.exists:
    - name: /opt/tomcat/webapps/website1/index.html

tees-logo.png:
  file.exists:
    - name: /opt/tomcat/webapps/website1/statics/images/logo.png

tees-logo_website1.png:
  file.exists:
    - name: /opt/tomcat/webapps/website1/statics/images/logo_website1.png

tees-notfound.gif:
  file.exists:
    - name: /opt/tomcat/webapps/website1/statics/images/notfound.gif

tees-sessionKeepAliveImage.png:
  file.exists:
    - name: /opt/tomcat/webapps/website1/images/sessionKeepAliveImage.png

tees-site.properties:
  file.exists:
    - name: /opt/jhc/ajb-2/config/site.properties

tees.properties:
  file.exists:
    - name: /opt/jhc/ajb-2/config/ajb-2.properties

tees-common-site.properties:
  file.exists:
    - name: /opt/jhc/ajb-2/config/common-site.properties

tees-environment.properties:
  file.exists:
    - name: /opt/jhc/ajb-2/config/environment.properties

tees-Admin.properties:
  file.exists:
    - name: /opt/jhc/ajb-2/config/Admin.properties

tees-log4j-Client.properties:
  file.exists:
    - name: /opt/jhc/ajb-2/config/log4j-Client.properties

tees-log4j-Admin.properties:
  file.exists:
    - name: /opt/jhc/ajb-2/config/log4j-Admin.properties

tees-website1.properties:
  file.exists:
    - name: /opt/jhc/ajb-2/config/website1.properties

tees-ehcache.xml:
  file.exists:
    - name: /opt/jhc/ajb-2/config/ehcache.xml

{% endif %}

#####################################################################################################################                                           DART CAPITAL SPECIFIC CONFIG
####################################################################################################################

{% if grains['host'] in ['BCA-AJT-TC-03', 'BCA-AJU-TC-03'] %}

dart-pom.properties:
  file.exists:
    - name: /opt/tomcat/webapps/website2/META-INF/maven/jhc.client.F63.web.figaroweb/website2/pom.properties

dart-pom.xml:
  file.exists:
    - name: /opt/tomcat/webapps/website2/META-INF/maven/jhc.client.F63.web.figaroweb/website2/pom.xml

dart-index.html:
  file.exists:
    - name: /opt/tomcat/webapps/website2/index.html

dart-logo.png:
  file.exists:
    - name: /opt/tomcat/webapps/website2/statics/images/logo.png

dart-notfound.gif:
  file.exists:
    - name: /opt/tomcat/webapps/website2/statics/images/notfound.gif

dart-sessionKeepAlive.png:
  file.exists:
    - name: /opt/tomcat/webapps/website2/images/sessionKeepAliveImage.png

dart.log:
  file.exists:
    - name: /opt/tomcat/logs/dart.log

dart-site.properties:
  file.exists:
    - name: /opt/jhc/website2/config/site.properties

dart-common-site.properties:
  file.exists:
    - name: /opt/jhc/website2/config/common-site.properties

dart-environment.properties:
  file.exists:
    - name: /opt/jhc/website2/config/environment.properties

dart-Admin.properties:
  file.exists:
   - name: /opt/jhc/website2/config/Admin.properties

dart-Client.properties:
  file.exists:
    - name: /opt/jhc/website2/config/Client.properties

dart-log4j-Client.properties:
  file.exists:
    - name: /opt/jhc/website2/config/log4j-Client.properties

dart-log4j-Admin.properties:
  file.exists:
    - name: /opt/jhc/website2/config/log4j-Admin.properties

dart-ehcache.xml:
  file.exists:
    - name: /opt/jhc/website2/config/ehcache.xml

dart-website2-client.log:
  file.exists:
    - name: /opt/tomcat/logs/website2-client.log

dart-website2-admin.log:
  file.exists:
    - name: /opt/tomcat/logs/website2-admin.log

{% endif %}

#####################################################################################################################                                           website3 SPECIFIC CONFIG
####################################################################################################################

{% if grains['host'] in ['BCA-AJT-TC-07', 'BCA-AJU-TC-07'] %}

website3-pom.xml:
  file.exists:
    - name: /opt/tomcat/webapps/website3/META-INF/maven/jhc.client.F63.web.figaroweb/website3/pom.xml

website3-pom.properties:
  file.exists:
    - name: /opt/tomcat/webapps/website3/META-INF/maven/jhc.client.F63.web.figaroweb/website3/pom.properties

website3-index.html:
  file.exists:
    - name: /opt/tomcat/webapps/website3/index.html

website3-logo.png:
  file.exists:
    - name: /opt/tomcat/webapps/website3/statics/images/logo.png

website3-notfound.gif:
  file.exists:
    - name: /opt/tomcat/webapps/website3/statics/images/notfound.gif

website3-sessionKeepAlive.png:
  file.exists:
    - name: /opt/tomcat/webapps/website3/images/sessionKeepAliveImage.png

website3-site.properties:
  file.exists:
    - name: /opt/jhc/website3/config/site.properties

website3.properties:
  file.exists:
    - name: /opt/jhc/website3/config/website3.properties

website3-common-site.properties:
  file.exists:
    - name: /opt/jhc/website3/config/common-site.properties

website3-environment.properties:
  file.exists:
    - name: /opt/jhc/website3/config/environment.properties

website3-Admin.properties:
  file.exists:
   - name: /opt/jhc/website3/config/Admin.properties

website3-Client.properties:
  file.exists:
    - name: /opt/jhc/website3/config/Client.properties

website3-log4j-Client.properties:
  file.exists:
    - name: /opt/jhc/website3/config/log4j-Client.properties

website3-log4j-Admin.properties:
  file.exists:
    - name: /opt/jhc/website3/config/log4j-Admin.properties

website3-ehcache.xml:
  file.exists:
    - name: /opt/jhc/website3/config/ehcache.xml

website3-website3.properties:
  file.exists:
    - name: /opt/jhc/website3/config/website3.properties


{% endif %}

#####################################################################################################################                       MONEY MATTERS SPECIFIC CONFIG
####################################################################################################################

{% if grains['host'] in ['BCA-AJT-TC-05', 'BCA-AJU-TC-05'] %}

website4-pom.xml:
  file.exists:
    - name: /opt/tomcat/webapps/website4/META-INF/maven/jhc.client.F63.web.figaroweb/ajb-1/pom.xml

website4-pom.properties:
  file.exists:
    - name: /opt/tomcat/webapps/website4/META-INF/maven/jhc.client.F63.web.figaroweb/ajb-1/pom.properties

website4-index.html:
  file.exists:
    - name: /opt/tomcat/webapps/website4/index.html

website4-logo.png:
  file.exists:
    - name: /opt/tomcat/webapps/website4/statics/images/logo.png

website4-notfound.gif:
  file.exists:
    - name: /opt/tomcat/webapps/website4/statics/images/notfound.gif

website4-sessionKeepAlive.png:
  file.exists:
    - name: /opt/tomcat/webapps/website4/images/sessionKeepAliveImage.png

website4-site.properties:
  file.exists:
    - name: /opt/jhc/ajb-1/config/site.properties

website4.properties:
  file.exists:
    - name: /opt/jhc/ajb-1/config/ajb-1.properties

website4-common-site.properties:
  file.exists:
    - name: /opt/jhc/ajb-1/config/common-site.properties

website4-environment.properties:
  file.exists:
    - name: /opt/jhc/ajb-1/config/environment.properties

website4-Admin.properties:
  file.exists:
   - name: /opt/jhc/ajb-1/config/Admin.properties

website4-log4j-Client.properties:
  file.exists:
    - name: /opt/jhc/ajb-1/config/log4j-Client.properties

website4-log4j-Admin.properties:
  file.exists:
    - name: /opt/jhc/ajb-1/config/log4j-Admin.properties

website4-ehcache.xml:
  file.exists:
    - name: /opt/jhc/ajb-1/config/ehcache.xml

website4-website3.properties:
  file.exists:
    - name: /opt/jhc/ajb-1/config/ajb-1.properties

{% endif %}

##################################################################################################################### THIS SECTION CHECKS THAT SERVICES ARE RUNNING ON EACH TOMCAT SERVER
####################################################################################################################

{% if grains['host'] in ['BCA-AJT-TC-04', 'BCA-AJU-TC-04', 'BCA-AJT-TC-07', 'BCA-AJU-TC-07'] %}

httpd:
  service.running:
    - name: httpd
    - enable: True

httpd.conf:
  file.exists:
    - name: /etc/httpd/conf/httpd.conf

php.conf:
  file.exists:
    - name: /etc/httpd/conf.d/php.conf

{% endif %}

rsyslog:
  service.running:
    - name: rsyslog
    - enable: True

salt-minion:
  service.running:
    - name: salt-minion
    - enable: True

sshd:
  service.running:
    - name: sshd
    - enable: True

ntpd:
  service.running:
    - name: ntpd
    - enable: True

check_jets:
  cmd.run:
    - name: ps aux | grep 'org.apache.catalina.startup.Bootstrap start' | grep -v grep

It may also be worth mentioning that I have used the above method in multiple areas across my state for the same purpose, yet targeting dev/test-server-01, 02, 03 etc without problems. It's specifically a problem with this section of code as other sections which target TEST-SERVER-04 in the state work fine (as I mentioned it runs 32/50)

**Tags:** salt, jinja, yaml

> **Comments:**
> **username_1**: I think you should share your whole file, as is it would be guessing to find what could be wrong somewhere. Sometimes the inner snippet not running is not the root cause, maybe you have another if statement not closed which prevent a block of the file to be evaluated.  
> **username_0**: @username_1 Do you have any recommendations as to where I could upload the file? It is large (not in size) and would be very time consuming to edit on stack exchange to make it readable.  
> **username_1**: Why that ? copy paste it, select the code and press CTRL+K to add the 4 spaces or click on the `{}` button. Unless it would extend the question up to 30 000 chars, there's no reason to not paste it here. If that's not a viable solution for you, maybe https://gist.github.com  
> **username_0**: @username_1 - I didn't know that was a possibility, thanks for that!  
> **username_1**: Glad it helped and you found the problem ;)  

---

## 1 answers

### Answer by username_0 on 2017-09-22. Score: 2 | Accepted answer

I have found the answer to my own question after some more investigation.

The reason the state was skipping the contents of my if statement was because the hostname of the server was in lower-case (god knows why). Therefore the in-built salt grains.item host which is called upon didn't recognise the server I was specifying.


---

