Automatically creating subdirectories?

205 views
Skip to first unread message

Douglas

unread,
Jun 19, 2009, 2:43:14 PM6/19/09
to Puppet Users
I'm relatively new to puppet.

Searched online, and could not find an answer to this. I have the
following manifest snippet...

class openvpn {
package { openvpn: ensure => latest }
file {
"/usr/share/openvpn/easy-rsa/2.0/keys":
ensure => directory, owner => root, group => root, mode =>
600,
file {
"/usr/share/openvpn/easy-rsa/2.0/keys/ca.crt":
source => "puppet://$server/openvpn/ca.crt",
owner => root, group => root, mode => 600,
require => File["/usr/share/openvpn/easy-rsa/2.0/keys"],
}
}

Puppet is complaining with...
Jun 19 11:35:59 node1 puppetd[3553]: (//Node[basenode]/openvpn/File[/
usr/share/openvpn/easy-rsa/2.0/keys]/ensure) change from absent to
directory failed: Cannot create /usr/share/openvpn/easy-rsa/2.0/
keys; parent directory /usr/share/openvpn/easy-rsa/2.0 does not exist

Shouldn't puppet automatically create all the subdirectories above usr/
share/openvpn/easy-rsa/2.0 directory for me? If not, do I need to go
and create dependancies for every single node in the directory
hierarchy? That seems a little crazy. Isn't there a better way?

Thanks,
Doug.






RijilV

unread,
Jun 19, 2009, 2:57:25 PM6/19/09
to puppet...@googlegroups.com


2009/6/19 Douglas <doug.g...@gmail.com>


I'm relatively new to puppet.

Searched online, and could not find an answer to this. I have the
following manifest snippet...
 

[snip]
 

Shouldn't puppet automatically create all the subdirectories above usr/
share/openvpn/easy-rsa/2.0 directory for me? If not, do I need to go
and create dependancies for every single node in the directory
hierarchy? That seems a little crazy. Isn't there a better way?

Thanks,
Doug.

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":

.r'



p.s.  puppet is smart enough to handle adding the dependency between the directory and the file within that directory so you don't need that one require you already have.  Also you can save yourself some typing by doing:

file {
    "/dir":
       ensure => directory,
       mode => 644;
   "/dir/file":
        content => "blah";
}

just note the ";" between items.



Peter Meier

unread,
Jun 19, 2009, 3:12:44 PM6/19/09
to puppet...@googlegroups.com
Hi

> Yeah, this is an old and know issue (unfortunately).
>
> Original bug report:
> http://projects.reductivelabs.com/issues/86

well bug or more a philosphical question? The comments in the bug report
describe a bit the problem puppet would run into if puppet would
auto-create them.

puppet manages resources and isn't just executing a bunch of commands in
a certain order.

cheers pete

Douglas Garstang

unread,
Jun 19, 2009, 3:13:49 PM6/19/09
to Puppet Users
Thanks. Good to know I wasn't missing something.
--
Regards,

Douglas Garstang
http://www.linkedin.com/in/garstang
Email: doug.g...@gmail.com
Cell: +1-805-340-5627

Thomas Bellman

unread,
Jun 22, 2009, 8:52:16 AM6/22/09
to puppet...@googlegroups.com
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

dirtree.rb
Reply all
Reply to author
Forward
0 new messages