Hi Christ,

Sorry, I missed use the class: class { 'keys': }. Now it works. Thanks for 
your time.

Thanks
Mohan L

On Sunday, May 10, 2015 at 7:32:37 AM UTC+5:30, Mohan L wrote:
>
> Hi Christ,
>
>
> # puppet apply -e '$keys_hash = hiera('sg-puppet-agent-14') notify { 
> $keys_hash: }'
>
> # puppet apply -e '$keys_hash = hiera('sg-puppet-agent-14') notify { 
> $keys_hash: }'
> Notice: Compiled catalog for sgptcomosbcppt01 in environment production in 
> 0.05 seconds
> Notice: {"ubuntu"=>{"user"=>"ubuntu", "type"=>"ssh-rsa", 
> "key"=>"AAAAB3NzaC1yc2EAAAADAQABAAABAQDJzdGydf2tdZYCkBRGx/SnlVKW+9q3Mqtf9vCrs0SaSkwDK4Q36hS40IVgmri2mjKeWFr5p92OgYY1hjZk4LLUAbVV8ItmPLqvmfrkOEwDCzmkbrUVa4BTKePWG0hOGAVYSQkS+1vhsTFhtznJMxsjRVwj8tO3s0fSnaXcovs9d4LwXhRbcDjzrAVRkk2d5/lSbjc/T4ZJ6oMKcGCxq02etJMoSBBQsEfRP/vULqKjoxJ96kb3Y43tU7gRzcVkXAyNqpXie8fD/FopoVi/uHIqkzotkOwztUYNt6C5LwV/W4ds5x3Zl7Jo4kqup2FOCs4oXSC3WxJI5FJ9WuPMtK1r"},
>  
> "root"=>{"user"=>"root", "type"=>"ssh-rsa", 
> "key"=>"AAAAB3NzaC1yc2EAAAADAQABAAABAQCqlo0PPGZ2XW1qBFuFgYmsGlT24I+v51tb7cRSAJeBouDPvfqBMBOX84ye4DsW3uRmFNXt/wdAr/QnEAlua5bSagVRC2t9X4lkcrFJSSfEA2J29Lh16pPzOK/HReo8R89wbEKfqrqZG/FNrjMB6YaAxBRJE0O9T6BDsMBCg6b8wb6DRPIKzuEkKkI9ywExVrVFOEANTsdS0oQq8exIlWHmnKwOf1R2Jl1FRgIHnJAfG29EoeY7Q+DlPZOBXqB+xamYj56h6FMb0ZLBOAirXm76bHbqJhzY5RbcW8HrxzvLBY1xfOlP4NMKWIxBNG1j2Je0WPU9gVDnq7/LoS0OuCtR"}}
> Notice: /Stage[main]/Main/Notify[{"ubuntu"=>{"user"=>"ubuntu", 
> "type"=>"ssh-rsa", 
> "key"=>"AAAAB3NzaC1yc2EAAAADAQABAAABAQDJzdGydf2tdZYCkBRGx/SnlVKW+9q3Mqtf9vCrs0SaSkwDK4Q36hS40IVgmri2mjKeWFr5p92OgYY1hjZk4LLUAbVV8ItmPLqvmfrkOEwDCzmkbrUVa4BTKePWG0hOGAVYSQkS+1vhsTFhtznJMxsjRVwj8tO3s0fSnaXcovs9d4LwXhRbcDjzrAVRkk2d5/lSbjc/T4ZJ6oMKcGCxq02etJMoSBBQsEfRP/vULqKjoxJ96kb3Y43tU7gRzcVkXAyNqpXie8fD/FopoVi/uHIqkzotkOwztUYNt6C5LwV/W4ds5x3Zl7Jo4kqup2FOCs4oXSC3WxJI5FJ9WuPMtK1r"},
>  
> "root"=>{"user"=>"root", "type"=>"ssh-rsa", 
> "key"=>"AAAAB3NzaC1yc2EAAAADAQABAAABAQCqlo0PPGZ2XW1qBFuFgYmsGlT24I+v51tb7cRSAJeBouDPvfqBMBOX84ye4DsW3uRmFNXt/wdAr/QnEAlua5bSagVRC2t9X4lkcrFJSSfEA2J29Lh16pPzOK/HReo8R89wbEKfqrqZG/FNrjMB6YaAxBRJE0O9T6BDsMBCg6b8wb6DRPIKzuEkKkI9ywExVrVFOEANTsdS0oQq8exIlWHmnKwOf1R2Jl1FRgIHnJAfG29EoeY7Q+DlPZOBXqB+xamYj56h6FMb0ZLBOAirXm76bHbqJhzY5RbcW8HrxzvLBY1xfOlP4NMKWIxBNG1j2Je0WPU9gVDnq7/LoS0OuCtR"}}]/message:
>  
> defined 'message' as '{"ubuntu"=>{"user"=>"ubuntu", "type"=>"ssh-rsa", 
> "key"=>"AAAAB3NzaC1yc2EAAAADAQABAAABAQDJzdGydf2tdZYCkBRGx/SnlVKW+9q3Mqtf9vCrs0SaSkwDK4Q36hS40IVgmri2mjKeWFr5p92OgYY1hjZk4LLUAbVV8ItmPLqvmfrkOEwDCzmkbrUVa4BTKePWG0hOGAVYSQkS+1vhsTFhtznJMxsjRVwj8tO3s0fSnaXcovs9d4LwXhRbcDjzrAVRkk2d5/lSbjc/T4ZJ6oMKcGCxq02etJMoSBBQsEfRP/vULqKjoxJ96kb3Y43tU7gRzcVkXAyNqpXie8fD/FopoVi/uHIqkzotkOwztUYNt6C5LwV/W4ds5x3Zl7Jo4kqup2FOCs4oXSC3WxJI5FJ9WuPMtK1r"},
>  
> "root"=>{"user"=>"root", "type"=>"ssh-rsa", 
> "key"=>"AAAAB3NzaC1yc2EAAAADAQABAAABAQCqlo0PPGZ2XW1qBFuFgYmsGlT24I+v51tb7cRSAJeBouDPvfqBMBOX84ye4DsW3uRmFNXt/wdAr/QnEAlua5bSagVRC2t9X4lkcrFJSSfEA2J29Lh16pPzOK/HReo8R89wbEKfqrqZG/FNrjMB6YaAxBRJE0O9T6BDsMBCg6b8wb6DRPIKzuEkKkI9ywExVrVFOEANTsdS0oQq8exIlWHmnKwOf1R2Jl1FRgIHnJAfG29EoeY7Q+DlPZOBXqB+xamYj56h6FMb0ZLBOAirXm76bHbqJhzY5RbcW8HrxzvLBY1xfOlP4NMKWIxBNG1j2Je0WPU9gVDnq7/LoS0OuCtR"}}'
> Notice: Finished catalog run in 0.03 seconds
>
>
> # cat site.pp
>
> class keys {
>   create_resources( "key", hiera('sg-puppet-agent-14') )
> }
>
> define key($user, $type, $key) {
>
> sshkeys::key { "$user":
>         key_name => "$user",
>         user     => "$user",
>         key => "$key",
>         type => "$type"
>
> }
>
> }
>
> # cat hiera.yaml
> ---
> :backends:
>   - yaml
> :hierarchy:
>   - defaults
>   - global
>
> :yaml:
> # datadir is empty here, so hiera uses its defaults:
> # - /var/lib/hiera on *nix
> # - %CommonAppData%\PuppetLabs\hiera\var on Windows
> # When specifying a datadir, make sure the directory exists.
>   :datadir: /etc/puppet/hieradata
>
>
>
> # cat defaults.yaml
> ---
> puppetmaster: 'sgptcomosbcppt01.sgposbc.com'
> default_ntp_server: 'server 1.in.pool.ntp.org'
> # hash with keys in the hiera structure. The hash is merged with 
> hiera_hash lookup
> sg-puppet-agent-14:
>   ubuntu:
>     user: 'ubuntu'
>     type: 'ssh-rsa'
>     key: 
> 'AAAAB3NzaC1yc2EAAAADAQABAAABAQDJzdGydf2tdZYCkBRGx/SnlVKW+9q3Mqtf9vCrs0SaSkwDK4Q36hS40IVgmri2mjKeWFr5p92OgYY1hjZk4LLUAbVV8ItmPLqvmfrkOEwDCzmkbrUVa4BTKePWG0hOGAVYSQkS+1vhsTFhtznJMxsjRVwj8tO3s0fSnaXcovs9d4LwXhRbcDjzrAVRkk2d5/lSbjc/T4ZJ6oMKcGCxq02etJMoSBBQsEfRP/vULqKjoxJ96kb3Y43tU7gRzcVkXAyNqpXie8fD/FopoVi/uHIqkzotkOwztUYNt6C5LwV/W4ds5x3Zl7Jo4kqup2FOCs4oXSC3WxJI5FJ9WuPMtK1r'
>   root:
>     user: 'root'
>     type: 'ssh-rsa'
>     key: 
> 'AAAAB3NzaC1yc2EAAAADAQABAAABAQCqlo0PPGZ2XW1qBFuFgYmsGlT24I+v51tb7cRSAJeBouDPvfqBMBOX84ye4DsW3uRmFNXt/wdAr/QnEAlua5bSagVRC2t9X4lkcrFJSSfEA2J29Lh16pPzOK/HReo8R89wbEKfqrqZG/FNrjMB6YaAxBRJE0O9T6BDsMBCg6b8wb6DRPIKzuEkKkI9ywExVrVFOEANTsdS0oQq8exIlWHmnKwOf1R2Jl1FRgIHnJAfG29EoeY7Q+DlPZOBXqB+xamYj56h6FMb0ZLBOAirXm76bHbqJhzY5RbcW8HrxzvLBY1xfOlP4NMKWIxBNG1j2Je0WPU9gVDnq7/LoS0OuCtR'
>
>
> when I do #puppet agent --test from client machine, it is not pushing the 
> keys,no error. It will be very helpful if you through some light on the 
> issue in above code.
>
> Thanks
> Mohan L    
>
>
>
> On Thursday, May 7, 2015 at 10:56:55 PM UTC+5:30, Christopher Wood wrote:
>>
>> On Thu, May 07, 2015 at 08:50:12AM -0700, Mohan L wrote: 
>> >    Dear All, 
>> >    I am new to Puppet. Recently started l learning it. 
>> >    I need to push multiple ssh keys for client machine,  
>> >    Here is what I have written: 
>> >    Hiera: 
>> >    # cat hiera.yaml | grep -v ^# 
>> >    --- 
>> >    :backends: 
>> >      - yaml 
>> >    :hierarchy: 
>> >      - global 
>> >    :yaml: 
>> >      :datadir: /etc/puppet/hieradata 
>> >      
>> >    # cat /etc/puppet/hieradata/global.yaml 
>> >    # hash with keys in the hiera structure. The hash is merged with 
>> >    hiera_hash lookup 
>> >    sshkeys::keys: 
>> >      sg-vm-agent-004: 
>> >        user: 'ubuntu' 
>> >        type: 'ssh-rsa' 
>> >        key: 
>> >   
>>  
>> 'AAAAB3NzaC1yc2EAAAADAQABAAABAQDJzdGydf2tdZYCkBRGx/SnlVKW+9q3Mqtf9vCrs0SaSkwDK4Q36hS40IVgmri2mjKeWFr5p92OgYY1hjZk4LLUAbVV8ItmPLqvmfrkOEwDCzmkbrUVa4BTKePWG0hOGAVYSQkS+1vhsTFhtznJMxsjRVwj8tO3s0fSnaXcovs9d4LwXhRbcDjzrAVRkk2d5/lSbjc/T4ZJ6oMKcGCxq02etJMoSBBQsEfRP/vULqKjoxJ96kb3Y43tU7gRzcVkXAyNqpXie8fD/FopoVi/uHIqkzotkOwztUYNt6C5LwV/W4ds5x3Zl7Jo4kqup2FOCs4oXSC3WxJI5FJ9WuPMtK1r'
>>  
>>
>> >    # cat site.pp 
>> >    $keys_hash = hiera_hash('sshkeys::keys',undef) 
>> >    $username=$keys_hash[$hostname]['user'] 
>> >    sshkeys::key { "$hostname": 
>> >        key_name => "$hostname", 
>> >        user     => "$username", 
>> >    } 
>> >    How to push multiply ssh keys to client? 
>>
>> For puppet <4, look into create_resources and defined types. 
>>
>> https://docs.puppetlabs.com/puppet/3.7/reference/lang_defined_types.html 
>>
>>
>> http://docs.puppetlabs.com/references/3.stable/function.html#createresources 
>>
>> For puppet 4, it's probably easier to loop over the hash keys. I haven't 
>> used this yet. 
>>
>>
>> https://docs.puppetlabs.com/puppet/latest/reference/future_lang_iteration.html
>>  
>>
>> >    thanks for your time 
>> > 
>> >    -- 
>> >    You received this message because you are subscribed to the Google 
>> Groups 
>> >    "Puppet Users" group. 
>> >    To unsubscribe from this group and stop receiving emails from it, 
>> send an 
>> >    email to [1][email protected]. 
>> >    To view this discussion on the web visit 
>> >    [2]
>> https://groups.google.com/d/msgid/puppet-users/d9125204-7e05-472c-8029-1cb6f0a1c476%40googlegroups.com.
>>  
>>
>> >    For more options, visit [3]https://groups.google.com/d/optout. 
>> > 
>> > References 
>> > 
>> >    Visible links 
>> >    1. mailto:[email protected] 
>> >    2. 
>> https://groups.google.com/d/msgid/puppet-users/d9125204-7e05-472c-8029-1cb6f0a1c476%40googlegroups.com?utm_medium=email&utm_source=footer
>>  
>> >    3. https://groups.google.com/d/optout 
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/51582bfa-5cbc-474c-92d3-60965732dc6d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to