recursive descent

109 views
Skip to first unread message

Stuart Cracraft

unread,
Dec 11, 2013, 5:25:04 PM12/11/13
to puppet...@googlegroups.com

I want to recursively descend infinitely through a directory tree in regards to ensuring:

  (a) owner, group, permission
  (b) existence of the full path, all the leaves, out to the final leaf, e.g.
       /somedir/somesubdir/{file1,file2,file3,somesubdirtoo} and so forth

This could be done trivially with an exec but is not pure-Puppet-ecosystem, obviously.

So my questions are, from a Puppet-puritan-perspective:

  is there a way to do (a)
  is there a way to do (b)
  is there a way to do (a)+(b)

and last:

  is there a way to do (a)+(b) in a reasonable period of time for a shallow tree of few leaves

Yours in squirrelhood,

Stuart


Stuart Cracraft

unread,
Dec 11, 2013, 5:36:05 PM12/11/13
to puppet...@googlegroups.com
The tree has to already exist. 

One would think having the ability
to instantiate a tree from a seedling would be useful. 


Sent from my iPhone
--
You received this message because you are subscribed to a topic in the Google Groups "Puppet Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/puppet-users/Hf6ReeSy2mE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/b9c95f80-9ae3-439b-a451-17327291524d%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Stuart Cracraft

unread,
Dec 11, 2013, 5:38:02 PM12/11/13
to puppet...@googlegroups.com


On Wednesday, December 11, 2013 2:36:05 PM UTC-8, Stuart Cracraft wrote:
The tree has to already exist. 

One would think having the ability
to instantiate a tree from a seedling would be useful. 


Sent from my iPhone

On Dec 11, 2013, at 2:25 PM, Stuart Cracraft <smcra...@gmail.com> wrote:


I want to recursively descend infinitely through a directory tree in regards to ensuring:

  (a) owner, group, permission
  (b) existence of the full path, all the leaves, out to the final leaf, e.g.
       /somedir/somesubdir/{file1,file2,file3,somesubdirtoo} and so forth

This could be done trivially with an exec but is not pure-Puppet-ecosystem, obviously.

So my questions are, from a Puppet-puritan-perspective:

  is there a way to do (a)
  is there a way to do (b)
  is there a way to do (a)+(b)

and last:

  is there a way to do (a)+(b) in a reasonable period of time for a shallow tree of few leaves

Yours in squirrelhood,

Stuart


--
You received this message because you are subscribed to a topic in the Google Groups "Puppet Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/puppet-users/Hf6ReeSy2mE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to puppet-users+unsubscribe@googlegroups.com.

jcbollinger

unread,
Dec 12, 2013, 10:17:17 AM12/12/13
to puppet...@googlegroups.com


On Wednesday, December 11, 2013 4:38:02 PM UTC-6, Stuart Cracraft wrote:

Yes.  Do you still have a question here, or does that blog post answer the question sufficiently for you?


John

Stuart Cracraft

unread,
Dec 12, 2013, 1:57:34 PM12/12/13
to puppet...@googlegroups.com
Sure does John.

Thanks for your interest!

Do we know when the Puppet 3.0 book is coming out?

It's showing as a very, very long delay at Amazon...

Andy Spiegl

unread,
Dec 17, 2013, 2:12:21 PM12/17/13
to puppet...@googlegroups.com
> > http://christian.hofstaedtler.name/blog/2008/11/puppet-managing-directories-recursively.html

I thought I had understood recursive directory management. It worked
fine until I switched to puppet v3 (Debian 3.3.2-1puppetla to be exact)
Since then, files in subdirs aren't copied anymore.

An example:
File {
owner => "nagios",
group => "nagios",
mode => '0644',
}
file { '/var/lib/nagios':
ensure => directory,
source => 'puppet:///modules/nagios/var_lib_nagios',
recurse => true,
}
file { '/var/lib/nagios/plugins':
ensure => directory,
recurse => true,
mode => '0775',
}
file { '/var/lib/nagios/bin':
ensure => directory,
recurse => true,
mode => '0775',
}

lama:~/.../puppet/modules/nagios> ls -la files/var_lib_nagios
total 8
drwxrwxr-x 2 andy users 4096 2013-11-15 15:56:23 bin/
drwxrwxr-x 2 andy users 4096 2013-11-25 12:01:14 plugins/

Why aren't these directories copied to /var/lib/nagios?
I tried setting recurselimit to '2' but that didn't help either.

Thanks for any hint!
Andy.


--
A mathematician is a machine for converting coffee into theorems. (Alfred Renyi)

Stuart Cracraft

unread,
Dec 17, 2013, 4:17:01 PM12/17/13
to puppet...@googlegroups.com
That is very, very disturbing.

yg...@comcast.net

unread,
Dec 17, 2013, 4:54:58 PM12/17/13
to puppet-users
Have you tried experimenting ?
Much of my Puppet savvy is from tinkering.

Try some code. See what works and what does not work.

"Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us."
Bill Waterson (Calvin & Hobbes)
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/d24784e1-769c-4666-b077-a8856c898ff1%40googlegroups.com.

Stuart Cracraft

unread,
Dec 17, 2013, 5:02:41 PM12/17/13
to puppet...@googlegroups.com
I don't have time to play hunt-the-wumpus. 
You received this message because you are subscribed to a topic in the Google Groups "Puppet Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/puppet-users/Hf6ReeSy2mE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/594141407.88154.1387317298820.JavaMail.root%40sz0126a.westchester.pa.mail.comcast.net.

Ben Ford

unread,
Dec 17, 2013, 7:31:30 PM12/17/13
to puppet...@googlegroups.com, puppe...@spiegl.de
If you override something in a recursive directory, you're overriding everything. The subdirectories are being managed explicitly by the resource managing them, not by a combination of it and the parent. Look inline below:


On Tuesday, December 17, 2013 11:12:21 AM UTC-8, Andy Spiegl wrote:
> > http://christian.hofstaedtler.name/blog/2008/11/puppet-managing-directories-recursively.html

I thought I had understood recursive directory management.  It worked
fine until I switched to puppet v3 (Debian 3.3.2-1puppetla to be exact)
Since then, files in subdirs aren't copied anymore.

An example:
  File {
    owner => "nagios",
    group => "nagios",
    mode  => '0644',
  }
  file { '/var/lib/nagios':
        ensure    => directory,
    source    => 'puppet:///modules/nagios/var_lib_nagios',
        recurse   => true,
  }


Manages /var/lib/nagios with recurse true.
 

  file { '/var/lib/nagios/plugins':
        ensure    => directory,
        recurse   => true,
        mode      => '0775',
  }


Completely takes precedence over File['/var/lib/nagios'] and manages '/var/lib/nagios/plugins' telling Puppet that all you care about is that it's a directory with mode 775. Notice that you no longer have a source for this subdirectory, so it's explicitly not managed.

If you add source => 'puppet:///modules/nagios/var_lib_nagios/plugins' then I suspect you'll get what you want.

Ben Ford

unread,
Dec 17, 2013, 7:37:29 PM12/17/13
to puppet...@googlegroups.com, puppe...@spiegl.de

  file { '/var/lib/nagios/plugins':
        ensure    => directory,
        recurse   => true,
        mode      => '0775',
  } 

I should also point out that this is unnecessary, as Puppet will automatically promote read permissions to read & execute permissions for directories. If you simply remove the second file declarations from your code, you'll have the behavior that I think you're expecting.


Andy Spiegl

unread,
Dec 18, 2013, 3:23:52 AM12/18/13
to puppet...@googlegroups.com
On 2013-12-17, 16:31, Ben Ford wrote:

> If you override something in a recursive directory, you're
> overriding everything.
I see, that makes sense.

> If you add source => 'puppet:///modules/nagios/var_lib_nagios/plugins' then
> I suspect you'll get what you want.
You are right, that did it. Thanks!

> I should also point out that this is unnecessary, as Puppet will
> automatically promote read permissions to read & execute permissions
> for directories.
No, not exactly as the mode definition is meant for the files in the
subdirectory. There are executables in "bin" and "plugins".

So, what would be a better way of changing the mode of some files
within a directory resource with "recurse" activated? Adding "source"
for all of them seems awkward...

Thanks for your help!
Andy.

--
Suburbia is where the developer bulldozes out the trees,
then names the streets after them.
(Bill Vaughan)

jcbollinger

unread,
Dec 18, 2013, 10:27:07 AM12/18/13
to puppet...@googlegroups.com


On Wednesday, December 18, 2013 2:23:52 AM UTC-6, Andy Spiegl wrote:
On 2013-12-17, 16:31, Ben Ford wrote:

> If you override something in a recursive directory, you're
> overriding everything.
I see, that makes sense.

> If you add source => 'puppet:///modules/nagios/var_lib_nagios/plugins' then
> I suspect you'll get what you want.
You are right, that did it.  Thanks!

> I should also point out that this is unnecessary, as Puppet will
> automatically promote read permissions to read & execute permissions
> for directories.
No, not exactly as the mode definition is meant for the files in the
subdirectory.  There are executables in "bin" and "plugins".

So, what would be a better way of changing the mode of some files
within a directory resource with "recurse" activated?  Adding "source"
for all of them seems awkward...


 
Sorry, Puppet does not do the kind of resource property merging that you seem to want.  As Ben wrote, when you have an explicit declaration of a File resource that otherwise would be managed via a recursive directory resource, the explicit declaration is the only one considered.  Consider that the sources of the /var/lib/nagios/{plugins,bin} directories needn't actually appear on the masters as subdirectories of the source for /var/lib/nagios -- expressing the sources explicitly is not awkward, it's appropriate.

There are a few things you could do to make this more palatable.  For example, you can keep the needed manifest code DRY and clear by using a variable to specify the sources:

  $nagios_source = 'puppet:///modules/nagios/var_lib_nagios'

  file { '/var/lib/nagios':
        ensure    => directory,
        source    => ${nagios_source},
        recurse   => true,
        mode      => '0664',
  }
  file { '/var/lib/nagios/plugins':
        ensure    => directory,
        source    => "${nagios_source}/plugins",
        recurse   => true,
        mode      => '0775',
  }
  file { '/var/lib/nagios/bin':
        ensure    => directory,
        source    => "${nagios_source}/bin",
        recurse   => true,
        mode      => '0775',
  }


Alternatively, packages are sometimes better than recursive File resources for managing directory trees.

Or you could abandon managing file modes for the whole /var/lib/nagios tree via File resources, and do it instead via an Exec.


John

Andy Spiegl

unread,
Dec 18, 2013, 11:39:12 AM12/18/13
to puppet...@googlegroups.com
On 2013-12-18, 07:27, jcbollinger wrote:
> For example, you can keep the needed manifest code DRY and clear by
> using a variable to specify the sources:

Good idea, thanks!
Andy.


--
The foolish man seeks happiness in the distance,
the wise grows it under his feet. -- James Oppenheim
Reply all
Reply to author
Forward
0 new messages