Subscribe to a recursive file...

1,710 views
Skip to first unread message

Craig Dunn

unread,
Mar 25, 2009, 10:16:35 AM3/25/09
to puppet...@googlegroups.com

Hi All....

I've got this configuration to manage bind, I want the exec to be run
whenever anything under /var/named or the file /etc/named.conf gets
updated....

file { "/etc/named.conf":
owner => root,
group => root,
mode => 0644,
require => Package["bind"],
source => "puppet:///dnsauth/etc/named.conf",
}
file { "/var/named":
owner => named,
group => named,
mode => 0644,
require => File["/etc/named.root.hints"],
source => "puppet:///dnsauth/var/named",
recurse => true,
force => true,
ignore => ".svn",
purge => true,
}
exec { "/etc/init.d/named reload":
subscribe => [ File["/var/named"],
File["/etc/named.conf"] ],
command => "/etc/init.d/named reload",
refreshonly => true,
}


Currently, if I modify /etc/named.conf the exec runs as expected, but if
I modify a file under /var/named it never gets run and nothing is
logged, but the file is pushed out ok.

Any ideas how to get this to work, we'd rather not add every single
file{} entry for everything under /var/named

TIA

Craig

Gary Law

unread,
Mar 25, 2009, 10:39:29 AM3/25/09
to puppet...@googlegroups.com, Craig Dunn
2009/3/25 Craig Dunn <li...@codenation.net>


Hi All....

I've got this configuration to manage bind, I want the exec to be run
whenever anything under /var/named or the file /etc/named.conf gets
updated....

        file { "/etc/named.conf":
                owner   =>      root,
                group   =>      root,
                mode    =>      0644,
                require =>      Package["bind"],
                source  =>      "puppet:///dnsauth/etc/named.conf",
        }
        file { "/var/named":
                owner   =>      named,
                group   =>      named,
                mode    =>      0644,
                require =>      File["/etc/named.root.hints"],
                source  =>      "puppet:///dnsauth/var/named",
                recurse =>      true,
                force   =>      true,
                ignore  =>      ".svn",
                purge   =>      true,
        }
        


I'd try to change the /var/named to this:-

file { "/var/named":
        ensure => directory,
        notify => Exec["/etc/init.d/named reload"],
        owner   =>      named,
        group   =>      named,
        mode    =>      0644,
        require =>      File["/etc/named.root.hints"],
        source  =>      "puppet:///dnsauth/var/named",
        recurse =>      true,
        force   =>      true,
        ignore  =>      ".svn",
        purge   =>      true,
 }

and remove the subscribes from the Exec

HTH

Gary

 
--
Gary Law

Craig Dunn

unread,
Mar 25, 2009, 10:51:52 AM3/25/09
to puppet...@googlegroups.com

> I'd try to change the /var/named to this:-
>
> file { "/var/named":
> ensure => directory,
> notify => Exec["/etc/init.d/named reload"],
> owner => named,
> group => named,
> mode => 0644,
> require => File["/etc/named.root.hints"],
> source => "puppet:///dnsauth/var/named",
> recurse => true,
> force => true,
> ignore => ".svn",
> purge => true,
> }
>
> and remove the subscribes from the Exec
>
> HTH
>
> Gary
>
>


Hi,

This didn't have any effect - still the same... heres the debug I get
after modifying a zone file under /var/named/zones, you'll see it pushes
the file out but never actually attempts to run the code...

# puppetd --verbose --no-daemonize --debug -o

Reopening log files
Compiled catalog for puppet in 0.17 seconds
Caching catalog at /var/lib/puppet/localconfig.yaml
Starting catalog run
(//Node[dev-mgmt]/dnsauth/File[/var/named/zones]/checksum) checksum
changed '{mtime}Wed Mar 25 14:03:37 +0000 2009' to '{mtime}Wed Mar 25
14:14:12 +0000 2009'
(Filebucket[/var/lib/puppet/clientbucket]) Adding
/var/named/zones/hosts.domain.co.uk.db(a1782f4546b5e3073361c4492b20fa0b)

(//Node[dev-mgmt]/dnsauth/File[/var/named/zones/hosts.domain.co.uk.db])
Filebucketed to puppet with sum a1782f4546b5e3073361c4492b20fa0b

(//Node[dev-mgmt]/dnsauth/File[/var/named/zones/hosts.domain.co.uk.db]/source)
replacing from source
puppet:///dnsauth/var/named/zones/hosts.domain.co.uk.db with contents
{md5}39a30e0190fa590180ff857a0a896c9c
Compiled catalog for host091.network.domain.co.uk in 0.10 seconds
(//Node[dev-mgmt]/dnsauth/File[/var/named/data]/checksum) checksum
changed '{mtime}Wed Mar 25 14:06:09 +0000 2009' to '{mtime}Wed Mar 25
14:14:14 +0000 2009'
Finished catalog run in 8.42 seconds

Cheers
Craig


Gary Law

unread,
Mar 25, 2009, 8:44:10 PM3/25/09
to puppet...@googlegroups.com
The following, which is very similar to what you posted, works for me in so far as it triggers the Exec if a subdirectory of /var/named is created, if a new file is created in the subdir, or if an existing file is modified in the subdir:

class rectest {
    exec { "/etc/init.d/named reload":
        command      =>     "/etc/init.d/named reload",
        refreshonly  =>      true,
  }

    file { "/var/named":
        notify       =>    Exec["/etc/init.d/named reload"],
        ensure       =>    directory,   
        owner        =>    glaw,
        group        =>    glaw,
  mode         =>    0644,
        source       =>    "puppet://sv01.garylaw.net/rectest/var/named",
        recurse      =>    true,
        force        =>    true,
        ignore       =>    ".svn",
        purge        =>    true,
    }
}



--
Gary Law

jcbollinger

unread,
Apr 22, 2013, 9:28:57 AM4/22/13
to puppet...@googlegroups.com


On Friday, April 19, 2013 3:21:26 PM UTC-5, Dennis Miller wrote:
This doesn't seem to work for me in THIS specific case:

-editing the file directly under /var/named

Adding a new file works fine, but editing an existing one doesn't trigger the exec.  I think the directory mtime doesn't change, and Puppet doesn't know that a change has happened.  Thoughts?


I think Puppet's File type is not up to this task in recursive directory form, at least not without a bit of help.  That could perhaps be characterized as a bug (so consider filing a ticket), but then again, the whole recursive file thing has always been ... let's say "quirky".

Dennis's observation suggests a possible workaround: always 'touch' the top-level directory on the master after making changes to its contents.  If it has subdirectories then you might need to do the same with them.

Alternatively, are there so many files, or are files added and removed frequently enough, that it would be prohibitive to manage each explicitly?  Recursive directory management should be viewed as a shortcut.  If it doesn't get you to where you need to be, however, then you may just need to abandon it.

Here's a crazy idea: I think it would be possible to write a pair of definitions that automate the procedure of declaring bona fide File resources for all the files in a directory tree.  You would use the generate() function to get a (full) listing of the target directory, and massage it into a hash of hashes that you can use with create_resources().  I surely make it sound simpler than it really is, but I think it's doable.

John

Erik Anderson

unread,
Apr 13, 2017, 3:39:05 PM4/13/17
to Puppet Users, gary...@gmail.com
This is really helpful, thank you. Unfortunately it looks like this behavior requires the `purge` param to be set to true :(
Reply all
Reply to author
Forward
0 new messages