if-statement - 盐州。如果变量在标准输出中有一些字
问题描述
有一个网页,上面有一大段文字。
如果 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:
cmd.run:
- name: 'powershell.exe WRITE-HOST have no Error'
{% else %}
module_run1:
cmd.run:
- name: 'powershell.exe WRITE-HOST have Error'
{%- endif -%}
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
解决方案
如果 curl 返回错误,我想配置状态以执行特定操作。
有一个称为http的 Salt 状态,它可以query
是一个 URL 并返回状态。使用它(而不是curl
),我们可以检查状态代码(200、201 等)以及匹配的文本。然后我们可以根据http.query
.
例子:
我添加了对状态码 200 的检查,- status: 200
如果您不关心状态码,可以省略。
check-application:
http.query:
- name: http://127.0.0.1:5001
- status: 200
- match: 'StatusDescription : OK'
app-running:
cmd.run:
- name: 'powershell.exe WRITE-HOST have no Error'
- require:
- http: check-application
app-not-running:
cmd.run:
- name: 'powershell.exe WRITE-HOST have Error'
- onfail:
- http: check-application
推荐阅读
- javascript - 外部类调用一个LitElement组件方法(传递html模板),组件方法更新其html模板
- javascript - 有没有办法使用 SurveyJS 将调查结果保存为 Json 或文本文件?
- python - 学习率对收敛速度没有影响?
- python - 如何打印列表中每个元素的第一个字母
- python - 如何将固定的 subplot2grid 排列的倍数绘制成一个图形?
- python - 当 Pandas 在多个带有颜色标签的子图中创建散点图时,无法设置 xlabel
- javascript - Need mmenu to react differently on desktops and mobile devices
- css - MaterializeCSS collapsible with IMAGE
- npm - 找不到模块“指挥官”
- algorithm - 堆栈是否是数据结构?