Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SaltStack: In a watch statement, how do I specify a directory where all files should be watched?

I would like the nginx service to restart whenever any file in the /etc/nginx/conf.d directory is created or modified.

There are a number of files in that directory, and rather than specifying particular files, I would like to watch for all changes.

I've tried this:

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

but the line - file: /etc/nginx/conf.d is not doing what I want.

This is the error:

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

I've also tried a number of variations including a trailing slash, but none of them work.

What should - file: /etc/nginx/conf.d/ be changed to?

like image 662
coffee-grinder Avatar asked May 17 '14 20:05

coffee-grinder


2 Answers

I'm using a glob for matching:

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

Here's the corrected snippet:

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

Also do note that salt can only watch other states that are already specified in your state file, so it will only watch files that are managed by salt itself.

If this doesn't work for you, then try to refer the following link for a different solution: http://intothesaltmine.org/blog/html/2012/12/18/using_watch_with_file_recurse.html

like image 183
nmadhok Avatar answered Sep 30 '22 18:09

nmadhok


According to issue 663 closed in February 2012, a watch on /path/* should watch recursively.

like image 44
Chris Martin Avatar answered Sep 30 '22 19:09

Chris Martin