peter Schiza
peter Schiza

Reputation: 387

Managing directory in Puppet

I have war, which content (some files) need to be changed before applied to client. So what i did is copy unzipped files to client, change files that i want to and zip that directory again on client. Everything works but after those operations i would like to clean (remove that temp directory for uncompressed files). Because firstly i declare resource like this:

file { 'temp-dir'
 path => 'temp',
 ensure => directory, 
 ...
} 

Puppet doesnt allow me to do this at the end of manifest:

 File ['temp-dir'] {
     ensure => absent, 
     ...
    }

So am i doing something wrong, or it's not possible with puppet?

Upvotes: 0

Views: 330

Answers (1)

Alex Harvey
Alex Harvey

Reputation: 15472

It is not possible in the Puppet DSL using File resources, but there are still ways of doing what you want to do.

If you write in your manifest:

file { '/tmp/mytemp':
  ensure => directory,
}
-> 
exec { 'do something': }
->
file { '/tmp/mytemp':
  ensure => absent,
}

Puppet interprets the two file resources as a declaration of two different, incompatible end-states and throws an error.

Puppet is a declarative language, and not one where you specify a sequence of steps.

You have a few options.

The best is probably to look into the puppet-archive module, because that provides some extensions designed for your specific use-case with support for clean up.

Another option is simply not to clean up the temp files at all. There is usually no real need to clean them up.

Another option again is to write your own custom types and providers in Ruby to handle your specific installation.

Finally, you could use an exec to manage the entire procedure, e.g.

exec { 'install war':
  command => 'wget ... -o /tmp/war.tmp ; ... ; rm -f /tmp/war.tmp',
  path    => '/bin',
}

Upvotes: 2

Related Questions