0

How I must configure a "init.pp" file for sending more than a file in the same class? What I have done is this:

class nagios {
        file { ['/usr/lib64/nagios/plugins/']:
                path => '/usr/lib64/nagios/plugins/',
                ensure => directory,
                notify => Service['nrpe'],
                source => ["puppet:///modules/mymodule/check_mem.sh",
                           'puppet:///modules/mymodule/check_mountpoint.sh'],
                sourceselect => all,
        }
        service { 'nrpe':
                ensure => 'running',
                enable => true,
        }
}

What I'm trying is sending two different files to the same remote folder and then restart service.

However, when I run puppet at client, I get these errors:

[...]
Error: Could not set 'file' on ensure: Is a directory - (/usr/lib64/nagios/plugins20170306-28992-j54k6x, /usr/lib64/nagios/plugins) at 153:/etc/puppet/modules/mymodule/manifests/init.pp
[...]
Error: /Stage[main]/Nagios/File[/usr/lib64/nagios/plugins/]/ensure: change from directory to file failed: Could not set 'file' on ensure: Is a directory - (/usr/lib64/nagios/plugins20170306-28992-j54k6x, /usr/lib64/nagios/plugins) at 153:/etc/puppet/modules/mymodule/manifests/init.pp

Where is my mistake?

Thanks.

1 Answers1

1

The sourceselect parameter only affects recursive directory copies. For single files, you need multiple file resources, as in that case, only the first file will be copied.

Alternately, when serving directories recursively, multiple sources can be combined by setting the sourceselect attribute to all.

(Source)

Your second problem is that you tell Puppet to ensure that the target is a directory. In that case, giving a source file doesn't make any sense - you can't save a file as a directory. You would need to set it to file or present.

Re your comment: Something like this should work:

    file { ['/usr/lib64/nagios/plugins/check_mem.sh']:
            ensure => "file",
            notify => Service['nrpe'],
            source => "puppet:///modules/mymodule/check_mem.sh",
    }

    file { ['/usr/lib64/nagios/plugins/check_mountpoint.sh']:
            ensure => "file",
            notify => Service['nrpe'],
            source => "puppet:///modules/mymodule/check_mountpoint.sh",
    }
Sven
  • 98,649
  • 14
  • 180
  • 226