Watch multiple files in a directory

658 views
Skip to first unread message

Arthur Lutz

unread,
Mar 20, 2013, 4:17:33 AM3/20/13
to salt-...@googlegroups.com
Hi list,

Does anyone know a way of watching multiple files in a directory in the
"watch" directive ?

For example : if the highstate adds or modifies a file in
/etc/apt/sources.d/ do "apt-get update"

I would need this with cmd.run (since I'd like to apply it to
backuppc/munin/shinken/monit)

We've tried some stuff with extend and watching multiple explicitly
defined files but it doesn't seem to work the way we expect it.

If this is not possible I'd be happy to add a ticket. Thanks in advance.

Arthur

--
Arthur Lutz - LOGILAB, Paris (France).
Formations - http://www.logilab.fr/formations/
D�veloppements - http://www.logilab.fr/services/
Plateforme Web S�mantique - http://www.cubicweb.org/

Denis Generalov

unread,
Mar 20, 2013, 4:25:18 AM3/20/13
to salt-...@googlegroups.com, Arthur Lutz
On Wed, 20 Mar 2013 09:17:33 +0100
Arthur Lutz <arthu...@logilab.fr> wrote:

> Hi list,
>
> Does anyone know a way of watching multiple files in a directory in the
> "watch" directive ?
>
> For example : if the highstate adds or modifies a file in
> /etc/apt/sources.d/ do "apt-get update"

There is only one way - list all files which you want to watch:

watch:
- file: /etc/apt/sources.d/a
- file: /etc/apt/sources.d/b
- file: /etc/apt/sources.d/c

It's because requisite (watch, require) doesn't look
at file or directory (etc) literally, it looks at state
which has id occasionally looks like file name you want
to watch.

>
> I would need this with cmd.run (since I'd like to apply it to
> backuppc/munin/shinken/monit)
>
> We've tried some stuff with extend and watching multiple explicitly
> defined files but it doesn't seem to work the way we expect it.
>
> If this is not possible I'd be happy to add a ticket. Thanks in advance.
>
> Arthur
>
> --
> Arthur Lutz - LOGILAB, Paris (France).
> Formations - http://www.logilab.fr/formations/
> Développements - http://www.logilab.fr/services/
> Plateforme Web Sémantique - http://www.cubicweb.org/
>
> --
> You received this message because you are subscribed to the Google Groups "Salt-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>


--
Denis Generalov <gian...@gmail.com>

Mike Chesnut

unread,
Mar 20, 2013, 11:46:16 AM3/20/13
to salt-...@googlegroups.com
If /etc/apt/sources.d is a key itself (i.e., as a file.directory), I believe you can simply watch it:

watch:
  - file: /etc/apt/sources.d

You could also use watch_in to do it the other way around.

/etc/apt/sources.d:
  - file.directory:
    <whatever else you have here>
  - watch_in:
    - your-apt-update-cmd

If those aren't options, I'd try a jinja loop to add several individual file watch directives, as Denis has shown.  I'd consider actually listing out all of the files in the directory by hand as a last resort, which wouldn't help in the situation where the list of files changes (rather than simply their contents).

Antoine Pitrou

unread,
Mar 20, 2013, 11:54:44 AM3/20/13
to salt-...@googlegroups.com
Le Wed, 20 Mar 2013 12:25:18 +0400,
Denis Generalov <gian...@gmail.com> a
écrit :

> On Wed, 20 Mar 2013 09:17:33 +0100
> Arthur Lutz <arthu...@logilab.fr>
> wrote:
>
> > Hi list,
> >
> > Does anyone know a way of watching multiple files in a directory in
> > the "watch" directive ?
> >
> > For example : if the highstate adds or modifies a file in
> > /etc/apt/sources.d/ do "apt-get update"
>
> There is only one way - list all files which you want to watch:
>
> watch:
> - file: /etc/apt/sources.d/a
> - file: /etc/apt/sources.d/b
> - file: /etc/apt/sources.d/c

From my experiments, "watch_in" works fine with file.recurse:

asterisk:
pkg:
- installed
service:
- running
file.recurse:
- name: /etc/asterisk
- require:
- pkg: asterisk
- watch_in:
- service: asterisk
- source: salt://etc/asterisk
- user: asterisk
- group: asterisk


Regards

Antoine.


Reply all
Reply to author
Forward
0 new messages