If statement 盐州。如果变量在stdout中有一些单词
有一个网页,上面有一大块文字 我想将状态配置为在curl返回错误时执行特定操作 如果变量不包含“StatusDescription:OK” 如何设置变量内部文本的检查If statement 盐州。如果变量在stdout中有一些单词,if-statement,salt-stack,salt,If Statement,Salt Stack,Salt,有一个网页,上面有一大块文字 我想将状态配置为在curl返回错误时执行特定操作 如果变量不包含“StatusDescription:OK” 如何设置变量内部文本的检查 {% set seqstat = salt['cmd.run']('powershell.exe curl http://127.0.0.1:5001 -UseBasicParsing') %} {% if seqstat is sameas '*StatusDescription : OK*' %} module_run:
{% set seqstat = salt['cmd.run']('powershell.exe curl http://127.0.0.1:5001 -UseBasicParsing') %}
{% if seqstat is sameas '*StatusDescription : OK*' %}
module_run:
cmd.run:
- name: 'powershell.exe WRITE-HOST have no Error'
{% else %}
module_run1:
cmd.run:
- name: 'powershell.exe WRITE-HOST have Error'
{%- endif -%}
我想将状态配置为在curl返回错误时执行特定操作
有一个名为Salt的状态,它可以查询URL并返回状态。使用它(而不是curl
),我们可以检查状态代码(200、201等)以及匹配的文本。然后,根据http.query的成功/失败,我们可以使用来运行后续状态
例如:
我添加了一个状态代码为200的检查,如果您不关心状态代码,您可以省略-status:200
检查应用程序:
http.query:
-姓名:http://127.0.0.1:5001
-现状:200
-匹配:“状态描述:确定”
正在运行的应用程序:
cmd.run:
-名称:“powershell.exe写入主机无错误”
-要求:
-http:检查应用程序
应用程序未运行:
cmd.run:
-名称:“powershell.exe写入主机有错误”
-onfail:
-http:检查应用程序
Salt Version:
Salt: 3002.1
Dependency Versions:
cffi: 1.12.2
cherrypy: unknown
dateutil: 2.7.3
docker-py: 3.4.1
gitdb: 2.0.5
gitpython: 2.1.11
Jinja2: 2.10
libgit2: 0.27.7
M2Crypto: Not Installed
Mako: 1.0.7
msgpack-pure: Not Installed
msgpack-python: 0.5.6
mysql-python: 1.3.10
pycparser: 2.19
pycrypto: 2.6.1
pycryptodome: 3.6.1
pygit2: 0.27.4
Python: 3.7.3 (default, Jul 25 2020, 13:03:44)
python-gnupg: 0.4.4
PyYAML: 3.13
PyZMQ: 17.1.2
smmap: 2.0.5
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.3.1
System Versions:
dist: debian 10 buster
locale: UTF-8
machine: x86_64
release: 4.19.0-6-amd64
system: Linux
version: Debian GNU/Linux 10 buster