RijilV wrote:

> Yeah, this is an old and know issue (unfortunately).
> 
> Original bug report:
> http://projects.reductivelabs.com/issues/86
> 
> 
> You can work around it with a hackish exec:
> 
> exec { "mkdir -p /usr/share/openvpn/easy-rsa/2.0/keys": }
> 
> then tack that exec as a require to your file "/usr/share/openvpn/easy-rsa/
> 2.0/keys":

Inspired by this discussion, I just wrote a custom function that
could help in doing this, which I have attached.  You would then
use it like this:

     $x = dirtree("/usr/share/openvpn", "easy-rsa/2.0/keys")
     file {
         $x: ensure => directory;
     }

dirtree() will return a list of all directories from /usr/share/openvpn
down to /usr/share/openvpn/easy-rsa/foo/bar.  Passing that list to the
file type will make sure those exists.  But, unlike using mkdir -p, it
will *not* create /usr or /usr/share, only /usr/share/openvpn and down.

Unfortunately, it seems that I need to assign the function return value
to a temporary variable ($x above).  I would have liked to do

     file {
         dirtree("/usr/share/openvpn", "easy-rsa/2.0/keys"):
             ensure => directory;
     }

but at least the pre 0.25.0 snapshot I'm testing this with gives me
a syntax error for that. :-(  I'll file a bug report for that.


        /Bellman

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

module Puppet::Parser::Functions
    newfunction(:dirtree, :type => :rvalue, :doc => "\
        Generate a list of pathnames.  Bla, bla, bla.
        ") \
    do |args|
        if args.length != 2
            self.fail("dirtree(): wrong number of arguments" +
                      " (#{args.length} for 2)")
        end
        topdir = args[0]
        subbottom = args[1]
        subdirs = []
        while subbottom != "."
            subbottom, component = File.split(subbottom)
            subdirs.unshift(component)
        end
        dir = topdir
        paths = [ dir ]
        while subdirs.length > 0
            component = subdirs.shift()
            dir = File.join(dir, component)
            paths.push(dir)
        end
        return paths
    end
end

Reply via email to