How to remove a directory?

4,211 views
Skip to first unread message

Swit Zerland

unread,
Apr 5, 2014, 7:27:01 PM4/5/14
to puppet...@googlegroups.com
Hello

I am writing a site.pp to automate some tasks performed on a Windows VM puppet agent and I would like to know how to remove recursively a directory.

Thanks by advance
S.

Dirk Heinrichs

unread,
Apr 7, 2014, 1:32:45 AM4/7/14
to puppet...@googlegroups.com
Am 06.04.2014 01:27, schrieb Swit Zerland:

I am writing a site.pp to automate some tasks performed on a Windows VM puppet agent and I would like to know how to remove recursively a directory.

Either use an exec, which includes an "onlyif" attribute to remove the tree with an OS command, or one file resource (with "ensure => absent") for each directory in the tree. The latter needs more wotk to set up, but has the advantage of being OS independent.

Finally, you could write a new "dirtree" module which provides a new resource for managing directory trees and make it available on Github ;)

HTH...

    Dirk
--

Dirk Heinrichs, Senior Systems Engineer, Engineering Solutions
Recommind GmbH, Von-Liebig-Straße 1, 53359 Rheinbach
Tel: +49 2226 1596666 (Ansage) 1149
Email: d...@recommind.com
Skype: dirk.heinrichs.recommind
www.recommind.com

jcbollinger

unread,
Apr 7, 2014, 10:31:28 AM4/7/14
to puppet...@googlegroups.com, d...@recommind.com


On Monday, April 7, 2014 12:32:45 AM UTC-5, Dirk Heinrichs wrote:
Am 06.04.2014 01:27, schrieb Swit Zerland:

I am writing a site.pp to automate some tasks performed on a Windows VM puppet agent and I would like to know how to remove recursively a directory.

Either use an exec, which includes an "onlyif" attribute to remove the tree with an OS command, or one file resource (with "ensure => absent") for each directory in the tree. The latter needs more wotk to set up, but has the advantage of being OS independent.

Finally, you could write a new "dirtree" module which provides a new resource for managing directory trees and make it available on Github ;)


Or use a Tidy resource to recursively clean out the directory, and an ordinary File resource with ensure => 'absent' to remove the directory.  Or maybe it would work to use just one File resource with ensure => 'absent', recurse => 'true'.


John

Felix Frank

unread,
Apr 8, 2014, 8:06:42 AM4/8/14
to puppet...@googlegroups.com
Hi,

On 04/07/2014 04:31 PM, jcbollinger wrote:
> Or maybe it would work to use just one File resource with ensure =>
> 'absent', recurse => 'true'.

I would expect this to be the case, and IIRC force => true will also be
necessary for non-empty directories (this may even lift the need to
recurse).

Cheers,
Felix

Renan Vicente

unread,
Apr 8, 2014, 8:11:09 AM4/8/14
to puppet...@googlegroups.com
  file {'remove_directory':
   ensure  => absent,
   path    => '/your/directory',
   recurse => true,
   purge   => true,
   force   => true,
Reply all
Reply to author
Forward
0 new messages