2

so i have a basic modification module which applies to all servers managed through hiera. One submodule is called "files" and puts the scripts to /usr/local/bin/ of each server. So it iterates through the files directory and copies corresponding files. This works fine if i add the module.

Now i want to make this module to be manageable over hiera via $enabled = true|false. The problem is, when setting the ensure => absent it deletes the bin dir and prints some errors messages that it cannot delete the files, apparently because the bin dir is already deleted. So what i want is to just delete the files and leave the bin dir itself.

Any ideas?

I stumbled upon this old bug which seems to describe the same issue which looks like have been patched.

UPDATE: The point is to not reference every file in the manifest. Thats why i want to use recurse.

    files/
    files/devvm
    files/devvm/script1.sh
    files/devvm/live.sh
    files/devvm-tpl.dev
    files/devvm-tpl.dev/testscript2.pl
    files/common
    files/common/change_hostname.sh
    files/srvDC221
    files/srvDC221/wurst
class basemodifications::files (
     $enabled = "true",
 ) {

    file { 'usrlocalbin':
      ensure => $enabled ? {
        "true" => present,
        "false" => absent,
      },
      recurse => true,
      ignore => "*~",
      purge => true,
      owner => root,
      group => root,
      path => "/usr/local/bin/",
      #force => true, #will delete the bin directory
      sourceselect => all,
      source => ["puppet:///modules/tebasemod/common", "puppet:///modules/tebasemod/${::tecluster}", "puppet:///modules/tebasemod/${::fqdn}",]
    }

}
err: /File[/usr/local/bin/wurst]/ensure: change from absent to file failed: Could not set 'file on ensure: No such file or directory - /usr/local/bin/wurst.puppettmp_6753

1 Answer 1

1

You want to ensure that a certain set of files are present or absent in the directory, right? You don't ever want Puppet to ever delete the directory itself and all its contents? Then you need to manage the resources individually rather than recursing. Somethign like

file { '/usr/local/bin':
  ensure => directory,
  owner => root,
  group => root,
}

$scripts = ['/usr/local/bin/script1.sh', '/usr/local/bin/live.sh']

file { $scripts:
      ensure => $enabled ? {
        "true" => file,
        "false" => absent,
      },
  owner => root,
  group => root,
  require => File['/usr/local/bin'],
}

Since you need the scripts to vary across hosts, you can set $scripts in hiera rather than the manifest.

4
  • this would mean i have to "know" / reference every file in the manifest. I want to avoid that, thats why im using recurse.
    – tommics
    Feb 6, 2014 at 12:53
  • If you want to Puppet to delete those files, but not the directory itself or other files in it that aren't managed by puppet, I don't think you have another option.
    – sciurus
    Feb 6, 2014 at 16:07
  • thanks for your help anyway. what do you think is the reason for the bug report? am i misreading it or does it subscribe the same task i am trying to achieve?
    – tommics
    Feb 12, 2014 at 10:25
  • In the bug reports they expect the directory to be deleted.
    – sciurus
    Feb 12, 2014 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.