SaltStack:在watch语句中,如何指定应该监视所有文件的目录?

时间:2014-05-17 20:56:52

标签: service nginx salt-stack

我希望只要创建或修改/etc/nginx/conf.d目录中的任何文件,就会重新启动nginx服务。

该目录中有许多文件,而不是指定特定文件,我想留意所有更改。

我试过这个:

nginx:
  pkg.installed:
    - name: nginx
  service:
    - running
    - enable: True
    - restart: True
    - watch:
      - file: /etc/nginx/nginx.conf
      - file: /etc/nginx/conf.d
      - pkg: nginx

但是- file: /etc/nginx/conf.d行并没有按照我的意愿行事。

这是错误:

      ID: nginx
Function: service.running
  Result: False
 Comment: The following requisites were not found:
                             watch:
                                 file: /etc/nginx/conf.d
 Changes: 

我也尝试过多种变体,包括尾部斜线,但都没有效果。

- file: /etc/nginx/conf.d/应该改成什么?

2 个答案:

答案 0 :(得分:23)

我使用glob进行匹配:

file: /etc/nginx/conf.d/*

以下是修正后的摘录:

nginx:
  pkg.installed:
    - name: nginx
  service:
    - running
    - enable: True
    - restart: True
    - watch:
      - file: /etc/nginx/nginx.conf
      - file: /etc/nginx/conf.d/*
      - pkg: nginx

另请注意,salt只能监视状态文件中已指定的其他状态,因此它只会监视由salt本身管理的文件。

如果这对您不起作用,请尝试引用以下链接以获取其他解决方案: http://intothesaltmine.org/blog/html/2012/12/18/using_watch_with_file_recurse.html

答案 1 :(得分:2)

根据2012年2月结束的issue 663/path/*上的手表应递归观看。