如何获取盐栈状态下的返回码



您知道如何从stdout解析数据并在其中进行搜索吗?

check_satellite_registration:
cmd.run:
- name: subscription-manager list

例如,请参见下面的返回数据。如何在stdout中评估Status ?

retcode:
0
stderr:
stdout:
Status: Subscribed

如果以上状态为"已订阅";然后继续执行状态,否则重做安装:

deploy the http.conf file:
file.managed:
- name: /etc/http/conf/http.conf
- source: salt://apache/http.conf

有几个选项。它们都涉及不使用状态进行检查,因为它不做任何有状态的事情。

deploy the http.conf file:
file.managed:
- name: /etc/http/conf/http.conf
- source: salt://apache/http.conf
- onlyif:
- subscription-manager list | grep 'Status: Subscribed'
do something else:
cmd.run:
- unless:
- subscription-manager list | grep 'Status: Subscribed'
{% set status = salt["cmd.run"]("subscription-manager list") %}
{% if "Status: Subscribed" in status %}
deploy the http.conf file:
file.managed:
- name: /etc/http/conf/http.conf
- source: salt://apache/http.conf
{% else %}
do something else:
cmd.run: []
{% endif %}

虽然如果你的"其他东西"操作应该导致状态变为已订阅,那么您应该这样做:

register satellite:
cmd.run:
- name: my-register-command
- unless:
- subscription-manager list | grep 'Status: Subscribed'
deploy the http.conf file:
file.managed:
- name: /etc/http/conf/http.conf
- source: salt://apache/http.conf
- require:
- register satellite

最新更新