I hope you have more moments of despair because that's nifty and I'll use it.

You could possibly use ruby's dirname and basename 
(http://ruby-doc.org/core-1.8.7/File.html) inside an inline template to do the 
directory/file split for you in a single resource. The parameters for 
permissions and ownership for file vs directory might get messy, though.

On Thu, Apr 26, 2012 at 12:55:59AM -0700, Amos Shapira wrote:
>    Hello,
> 
>    Like many others, I once again had to deal with creation of deep directory
>    trees with puppet. I did the usual:
>    file { [ "/a", "/a/b/", "/a/b/c"...]:
>      ensure => directory
>    }
>    And again got sick of it. I still didn't find a good answer for it on the
>    web so here is what I came up with in a moment of despair:
> 
>    define core::mkdirp($owner = undef, $group = undef) {
>      exec { "mkdir -p ${name}":
>        creates => $name,
>      }
> 
>      file { $name:
>        ensure => 'directory',
>        require => Exec["mkdir -p ${name}"],
>        owner => $owner,
>        group => $group,
>      }
>    }
> 
>    Usage:
> 
>    core::mkdirp { "/a/b/c/d":
>      owner => $user,
>      group => $group,
>    }
> 
>    file { "/a/b/c/d/file.txt":
>     require => Core::Mkdirp["/a/b/c/d"],
>    ...
>    }
> 
>    So far it works beautifully for me but I want to hear what the community
>    thinks of it and whether there is a nicer solution I'm missing.
> 
>    Thanks.
> 
>    --Amos
> 
>    --
>    You received this message because you are subscribed to the Google Groups
>    "Puppet Users" group.
>    To view this discussion on the web visit
>    [1]https://groups.google.com/d/msg/puppet-users/-/ozFNn2oUGCQJ.
>    To post to this group, send email to puppet-users@googlegroups.com.
>    To unsubscribe from this group, send email to
>    puppet-users+unsubscr...@googlegroups.com.
>    For more options, visit this group at
>    http://groups.google.com/group/puppet-users?hl=en.
> 
> References
> 
>    Visible links
>    1. https://groups.google.com/d/msg/puppet-users/-/ozFNn2oUGCQJ

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to