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 Answer 1

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",
    }
5
  • But I think there can only be one "file" resource in a class... so if I have created a "nagios" class, in that class I can just send a file, aren't you? Commented Mar 6, 2017 at 12:22
  • No, there can be multiple file resources in a class, but they all need to have different names. Usually, I just name them after the target file names and Puppet uses this as the default value for target.
    – Sven
    Commented Mar 6, 2017 at 12:24
  • How do you that? I'm new in Puppet... Commented Mar 6, 2017 at 12:29
  • Please see my edit:
    – Sven
    Commented Mar 6, 2017 at 12:30
  • Thaaaaaanksss!!! Commented Mar 6, 2017 at 13:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .