ensure directory absent

113 views
Skip to first unread message

Albert Shih

unread,
Oct 19, 2015, 12:40:45 PM10/19/15
to puppet...@googlegroups.com
Hi

Stupid question :

I have a module who install some file/directory. I pass a parameter
"ensure" inside this module.

I can do

class my_module ($ensure ='present') {

file { 'file0':
ensure => $ensure
etc.

}

so I can call my class with " ensure => 'absent' " to cleanup.

But I don't known how to do the same thing with directory. Is they are any
easy/clean way to do that ?

I know I can do something like

if ensure = 'present'

{ file {'directory':} }
else
{ exec {'rmdir directory'}}

But seem not very clean for me.

Regards.

JAS

--
Albert SHIH
DIO bâtiment 15
Observatoire de Paris
5 Place Jules Janssen
92195 Meudon Cedex
France
Téléphone : +33 1 45 07 76 26/+33 6 86 69 95 71
xmpp: j...@obspm.fr
Heure local/Local time:
lun 19 oct 2015 14:37:03 CEST

Christopher Wood

unread,
Oct 19, 2015, 1:44:01 PM10/19/15
to puppet...@googlegroups.com
I think the "force" parameter is the answer to your immediate question.

http://docs.puppetlabs.com/references/latest/type.html#file-attribute-force

That comes with the usual warning that automated recursive deletion has a higher than usual risk of removing something you actually needed. Since empty directories are often inert, possibly you might investigate if "purge" is a better fit for you?

http://docs.puppetlabs.com/references/latest/type.html#file-attribute-purge
> --
> 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/20151019124041.GA5260%40pcjas.obspm.fr.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages