passing more parameters to define

30 views
Skip to first unread message

A. Gorlov

unread,
Mar 24, 2014, 2:46:20 AM3/24/14
to puppet...@googlegroups.com
Hi All.
How I post more parameters to define,  for example key type and fqdn   in this sample?

$keys = [[ "key1", "key2" ]
pubkey { $keys: user => $login  }

define pubkey($user) {
      ssh_authorized_key { "${user}@fqdn-${name}":
        ensure => present,
        key    => $name,
        user   => $user,
        type   => dsa,
      }
    }

Peter Bukowinski

unread,
Mar 24, 2014, 10:54:15 AM3/24/14
to puppet...@googlegroups.com
Parameters can be passed in as a comma-separated list:

define pubkey ($user, $key_type, $fqdn) { ... }

You can also set defaults for the parameters where it makes sense:

define my_type ($param1 = "foo" , $param2 = "bar", $param3) { ... }

--
Peter Bukowinski

A. Gorlov

unread,
Mar 24, 2014, 12:19:43 PM3/24/14
to puppet...@googlegroups.com
This is done already. 
question about changes in

$keys = [ "key1", "key2" ]
pubkey { $keys: user => $login  } 

to post some other values to define



понедельник, 24 марта 2014 г., 18:54:15 UTC+4 пользователь Peter Bukowinski написал:

jcbollinger

unread,
Mar 25, 2014, 1:47:15 PM3/25/14
to puppet...@googlegroups.com


On Monday, March 24, 2014 11:19:43 AM UTC-5, A. Gorlov wrote:
This is done already. 
question about changes in

$keys = [ "key1", "key2" ]
pubkey { $keys: user => $login  } 

to post some other values to define


A defined type is just a resource type.  You can assign as many parameters as you like (of those supported by the definition) using the normal resource-declaration syntax.  The definition presented as an example defines only one parameter, but all resource types support all the metaparameters:

pubkey { $keys:
  user => $login,
  require => Package['ssh']
}

If you want the defined type to accept additional ordinary parameters then you need to add them to the parameter list in its definition:

define pubkey($user, $key, $fqdn) {
  ...
}


If, however, you are asking how to pass different parameter values for different elements of the array-valued resource title, you have to get more creative.  You could consider using the create_resources() function instead of a standard declaration (http://docs.puppetlabs.com/references/3.stable/function.html#createresources), or you could do similar manually by putting all the wanted parameters in a hash keyed on user, and have the definition pull them out instance $name / $title.


John

Reply all
Reply to author
Forward
0 new messages