On Thu, Sep 20, 2012 at 07:34:44PM -0700, Hiu wrote:
> hi Paul,
> 
> 
> I am pretty to code the puppet codes. I try the options that you suggested 
> about creating the define type. But, I am still stuck in the middle.
> 
> Here is my code.
> $pub_keys=['XXXXXX', 'YYYYY', 'ZZZZZZ' ]
> 
> define add_authkeys (user="hiu", key) {
>         ssh_authorized_key { "$hiu":
>                 name => "hiu@$fqdn",
>                 ensure => present,
>                 type => ssh-rsa,
>                 key => $key,
>                 user => $user,
>         }
> }
> 
> 
> class base::config_authorized_keys {
>         add_authkeys { "hiu@$fqdn":
>                  key => $pub_keys,
>         }
> }
> 
> 
> the result is something that unexpected. my authorized keys are something 
> like this:
> 
> ssh-rsa XXXXYYYYYYYYZZZZZZZZZ
> 
> instead of 
> 
> ssh-rsa XXXXXXXX
> ssh-rsa YYYYYY
> ssh-rsa ZZZZZZZ
> 
> 
> can you please advise? thank you.
> 
The idea is to pass an array as a resource title. e.g.

    file { ['/foo', '/bar' ]: ensure => directory}

is the same as decalaring

    file { '/foo': ensure => directory}
    file { '/bar': ensure => directory}

You can now define a resource that takes a *key* as a title. This way
passing an array of keys multiple resources are created. The title is
available as $name. $user has to be passed as a parameter.

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

Now in your base class:

    class base::config_authorized_keys {
      $keys = [ "aaa", "bbb" ]
      pubkey { $keys:
        user => 'hiu',
      }
    }

Again, this is the same as declaring

    pubkey { "aaa": user => hiu }
    pubkey { "bbb": user => hiu }

-Stefan

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to