I'm not noticing the problem, but maybe it would help to see some other code.
I just uploaded my mounts module to github. It has one place that uses a 
function from Example42, but that can be replaced with a normal hiera call.

https://github.com/snemetz/Puppet_mounts

I have a few modules that use this method, but I need time to document and 
clean them up a bit, before releasing them.
Mounts is one of the simpler ones.

Steven

Date: Sat, 9 Feb 2013 20:15:55 -0800
From: rai...@gmail.com
To: puppet-users@googlegroups.com
Subject: Re: [Puppet Users] hiera query yaml parameters

When trying to separate user information in a yaml file, I encounter two 
issues. 
1. when I use the yaml file in init.pp under my user account module,  it gives 
following errors. ssh_user_hash is the assigned in class  as  "$ssh_user_hash = 
hiera(ssh_users)"===root@vm1:/etc/puppet/manifests# puppet apply --verbose 
nodes.ppInfo: Loading facts in 
/etc/puppet/modules/stdlib/lib/facter/puppet_vardir.rbInfo: Loading facts in 
/etc/puppet/modules/stdlib/lib/facter/facter_dot_d.rbInfo: Loading facts in 
/etc/puppet/modules/stdlib/lib/facter/pe_version.rbInfo: Loading facts in 
/etc/puppet/modules/stdlib/lib/facter/root_home.rbWarning: Could not retrieve 
fact fqdnWarning: Unrecognised escape sequence '\!' in file 
/etc/puppet/manifests/nodes.pp at line 12Warning: Host is missing hostname 
and/or domain: vm1Error: ssh_user_hash is not an hash or array when accessing 
it with user1 at /etc/puppet/modules/plm-accounts/manifests/init.pp:41 on node 
vm1
Error: ssh_user_hash is not an hash or array when accessing it with user1 at 
/etc/puppet/modules/plm-accounts/manifests/init.pp:41 on node vm1===
2.if I move the hiera output to node.pp, it can run on host vm1, which is my 
puppet master with yaml file on it. But it can't run on other puppet client 
server as it says can't find yaml file.===Error: Could not find data item 
ssh_users in any Hiera data file and no default supplied at 
/etc/puppet/manifests/nodes.pp:1 on node vm2
===
Here is my yaml file and init.pp in my user module file.#more 
/var/lib/hiera/OpsUser.yaml---ssh_users:user1 :        FullName : "User1"       
 additional_groups : "adm"        shell : "/bin/bash"        gid : 1003        
uid : 1003        pwhash : "$1$E7OvghG0$OmZMtTbQ2uYf5GA5u7RSH1"        ssh_key 
:                 type : "ssh-rsa"                key : 
"AAAAB3NzaC1yc2EAAAABJQAAAIBqOaxEVoWs69JM1H5jpzW7JvIwuanN4VW7F+uDVI1sii6BjROmYgYCvVoH+9/c3K5MNxqk35DHlFffgFk0b3o24Qa4RZZgxnUPTxsRIScaHQlr4/flYw643zVSwBpiEdBUfpRincUiaYfy6SCPu3aiKRyFgxZ6VByExrbHLwsz5w=="
                comment : "us...@yahoo.com"
root@vm1:/var/lib/hiera# more /etc/puppet/modules/plm-accounts/manifests/init.pp
class plm-accounts {    #exec {    #"/bin/echo user1:abc123 | 
/usr/sbin/chpasswd":    #onlyif => "/bin/egrep -q '^user1:\!:' /etc/shadow",    
#}
$ssh_user_hash = hiera(ssh_users)  $user_keys = keys($ssh_user_hash)  notice (" 
keys are $ssh_user_hash" )  if is_array ($user_keys) {    add_users { 
$user_keys: }  }
  define add_users {    $user_uid = $ssh_user_hash[$name][uid]     $real_name = 
$ssh_user_hash[$name][FullName]    notice ( "$user_uid is $real_name ")    
plm-accounts::virtual { "$name" :      uid => $user_uid,      realname => 
$real_name,        }plm-accounts::add_ssh_key { $name :      key => 
"${ssh_user_hash[$name][ssh_key][key]}",       type => 
"${ssh_user_hash[$name][ssh_key][type]}"                              }  }}



On Tuesday, February 5, 2013 12:00:25 PM UTC-5, roadtest wrote:you are right 
again:-) 
For people who are new to puppet,  here is the installation instruction - 
http://forge.puppetlabs.com/puppetlabs/stdlib.  stdlib is built in Puppet 
Enterprise and needs to be installed for community version.
cheers,
carl

On Tuesday, February 5, 2013 11:28:46 AM UTC-5, Steven wrote:



keys comes form the PuppetLab's stdlib module
So does is_array and a bunch of other nice functions


Steven
 
Date: Tue, 5 Feb 2013 07:12:45 -0800
From: rai...@gmail.com
To: puppet...@googlegroups.com
Subject: Re: [Puppet Users] hiera query yaml parameters

Steven, thanks for your reply!  You are right. It is unnecessary using 
create_resource to query yaml parameters. It can be done directly as following:
$sshd_hash = hiera(os_users)$server_ssh_keys = 
$sshd_hash[$username][ssh_keys][key]
format of my os_users yaml file was not correct, that is why it failed me. 
Btw, there is no keys function in puppet.
Cheers,
carl


On Sunday, February 3, 2013 10:21:25 PM UTC-5, Steven wrote:



You can read the hash directly, create_resource is not needed (may or may not 
be desired)

$user_defs = hiera('os_users') will give you the full hash

What I tend to do for this type of data structure is:

$user_defs = hiera('os_users')
$user_keys = keys($user_defs)
if is_array($user_keys) {
  process_users { $user_keys:; }
}

define process_users {
  # Do whatever you want for each element of the hash
  # $name will be the hash key
  # $user_defs[$name] is the hash of the current item
  # $user_defs[$name]['comment'] to access the user's comment field
}


Steven

From: yg...@comcast.net
Subject: Re: [Puppet Users] hiera query yaml parameters
Date: Sun, 3 Feb 2013 19:19:25 -0500
To: puppet...@googlegroups.com

Could you show your solution, please ?
I would like to see how you did it.
On Feb 3, 2013, at 6:46 PM, roadtest wrote:
I figure out the solution. 
Using the create_resource to convert YAML to a hash array, then I can query 
retrieve every individual value.  If there is better way, feel free to share 
with group.
carl

On Saturday, February 2, 2013 3:25:33 PM UTC-5, roadtest wrote:Hello,
I have a yaml data file containing user account with following 
information.#more users.yaml---os_users: user1:  locked: false  comment: System 
Operator  uid: '700'  gid: '700'  groups:  - admin  - sudonopw  sshkeys:  - 
ssh-rsa 
AAAAB3NzaC1yc2EAAAABIwAAAQEAwLBhQefRiXHSbVNZYKu2o8VWJjZJ/B4LqICXuxhiiNSCmL8j+5zE/VLPIMeDqNQt8L
 user2:  locked: true  comment: Test Locked Account  uid: '701'  gid: '701'  
groups:  - admin  - sudonopw  sshkeys:  - ssh-rsa 
AAAAB3NzaC1yc2EAAAABIwAAAQEAwLBhQefRiXHSbVNZYKu2o8VWJjZJ/B4LqICXuxhiiNSCm
I can search os_users information like following:#hiera -c /etc/hiera.yaml 
os_users{"user1"=>{"groups"=>["admin", "sudonopw"], "locked"=>false, 
"comment"=>"System Operator", "uid"=>"700", "sshkeys"=>["ssh-rsa 
AAAAB3NzaC1yc2EAAAABIwAAAQEAwLBhQefRiXHSbVNZYKu2o8VWJjZJ/B4LqICXuxhiiNSCmL8j+5zE/VLPIMeDqNQt8L"],
 "gid"=>"700"}, "user2"=>{"groups"=>["admin", "sudonopw"], "locked"=>true, 
"comment"=>"Test Locked Account", "uid"=>"701", "sshkeys"=>["ssh-rsa 
AAAAB3NzaC1yc2EAAAABIwAAAQEAwLBhQefRiXHSbVNZYKu2o8VWJjZJ/B4LqICXuxhiiNSCm"], 
"gid"=>"701"}}
My question is how I can get value of os_users -> user1 -> sshkeys. I 
tried:#hiera -c /etc/hiera.yaml os_users[user1[sshkeys]]nil
Could you please advise whether this is doable or direct me to some document?
Thanks in advance,
carl


-- 

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 puppet-users...@googlegroups.com.

To post to this group, send email to puppet...@googlegroups.com.

Visit this group at http://groups.google.com/group/puppet-users?hl=en.

For more options, visit https://groups.google.com/groups/opt_out.

 

 







-- 

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 puppet-users...@googlegroups.com.

To post to this group, send email to puppet...@googlegroups.com.

Visit this group at http://groups.google.com/group/puppet-users?hl=en.

For more options, visit https://groups.google.com/groups/opt_out.

 

 
                                          





-- 

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 puppet-users...@googlegroups.com.

To post to this group, send email to puppet...@googlegroups.com.

Visit this group at http://groups.google.com/group/puppet-users?hl=en.

For more options, visit https://groups.google.com/groups/opt_out.

 

 
                                          




-- 

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 puppet-users+unsubscr...@googlegroups.com.

To post to this group, send email to puppet-users@googlegroups.com.

Visit this group at http://groups.google.com/group/puppet-users?hl=en.

For more options, visit https://groups.google.com/groups/opt_out.

 

 
                                          

-- 
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 puppet-users+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to