saltstack cmd状态模块和条件判断

这个使用情况是需要在minion上执行命令时用到的.

示例:

apache-auth:

  pkg.installed:

    - name: httpd-tools

  cmd.run:

    -name: htpasswd -bc /etc/httpd/conf/htpasswd_file

 

但是会遇到一个问题,就是每次执行配置文件,这个命令都会执行.

所以需要做一个判断.可以再命令模块后面加一个unless,如果unless返回一个true就不执行.

apache-auth:

  pkg.installed:

    - name: httpd-tools

  cmd.run:

    -name: htpasswd -bc /etc/httpd/conf/htpasswd_file

    - unless: test -f  /etc/httpd/conf/htpasswd_file

posted @ 2019-03-13 15:17  auxiaoliu  阅读(715)  评论(0)    收藏  举报