Report abuse

Function

1
2
3
4
5
6
7
module Puppet::Parser::Functions
   newfunction(:currhost_containedin, :type => :rvalue) do |args|
      currhost = lookupvar('hostname')
      return args[0].include("#{currhost}")
   end
end

Manifest example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class ssh_keys {
   # User keys
   @ssh_userkeys {
      "storage":
         privkeyname => "id_rsa",
         fromhosts   => ["log2","universe"],
         dotsshpath  => "/home/storage/.ssh";
   }

   define ssh_userkeys( $dotsshpath, $privkeyname, $type = "rsa", $fromhosts ){
      $copypriv = currhost_containedin($fromhosts)
      if $copypriv == $hostname {
         file { "privkey_${name}_${privkeyname}":
            owner   => $name,
            group   => $name,
            ensure  => "file",
            path    => "$dotsshpath/$privkeyname",
            mode    => "0600",
            content => $privkey_contents,
            require => File[$dotsshpath, $authkeysfile];
         }
      }
   }
}

Failure message

1
2
3
4
5
root@foo:~# puppetd --test --ignorecache
info: Retrieving facts
err: Could not retrieve catalog: undefined method `include' for "log2":String at /etc/puppet/manifests/definitions/definitions.pp:177 on node foo.domain.tld
warning: Not using cache on failed catalog