saltstack中onchange

最近需要用saltsatck实现程序批量更新,假设脚本名字为test,需求为:当有新的脚本上传到files中,更新/home/data/test/test文件,并重启服务,实例如下:

test_restart:
  cmd.run:
    - cwd: /home/data/test
    - name: /bin/bash restart.sh
    - onchanges:
      - file: /home/data/test/test

/home/data/test/test:
  file.managed:
    - source: salt://files/test
    - user: root
    - group: root
    - mode: 755
    - backup: minion

 

开始之前使用watch或者watch_in来检测文件边发,如果文件变化了就重启,没有变化就不重启,结果发现不管怎么样,cmd.run都会执行,最后查看官网文档有onchange这个参数,用这个就可以了。。。。

原因还在研究,看来是对watch理解不够透彻。

 

查询官网:

If a state should only execute when another state has changes, and otherwise do nothing, the new onchanges requisite should be used instead of watch. watch is designed to add additional behavior when there are changes, but otherwise the state executes normally.

已经告知了原因,问题解决。

 

posted on 2018-05-07 17:37  老|王  阅读(285)  评论(0编辑  收藏  举报