一千萬個為什麽

搜索

Salt State正在針對除一個之外的所有服務器運行,為什麽?



I recently asked a question here: Is it possible to use multiple if statements in a salt state?

由於答案,我設法將狀態更新為僅檢查if語句中定義的特定服務器上存在的特定文件。然而,一臺服務器存在一個問題,狀態運行正常,並且沒有錯誤,但是它只檢查TEST-SERVER-04上的32個文件,而'DEV'對應(在相同的if語句中定義)有所有50個文件被檢查。

對於我的生活,我無法弄清楚為什麽!如果我嘗試直接對服務器運行狀態(即salt'test-server-04'state.sls filecheck'),它仍然會執行相同的操作!我反復檢查了我的語法,檢查了白線等,但無濟於事!我相信有人能夠指出我在這裏做錯了什麽!

以下是受影響的代碼片段:

########################################################################################################################//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

值得一提的是,為了達到同樣的目的,我在整個州的多個領域都使用了上述方法,但是沒有問題地針對dev/test-server-01,02,03等。這段代碼特別是一個問題,因為其他部分的目標TEST-SERVER-04在狀態正常工作(正如我提到它運行32/50)

轉載註明原文: Salt State正在針對除一個之外的所有服務器運行,為什麽?

一共有 1 個回答:

經過多次調查,我找到了自己問題的答案。

國家跳過我的if語句的內容的原因是因為服務器的主機名是小寫的(上帝知道為什麽)。因此,被調用的內置salt grains.item主機不能識別我指定的服務器。