On Friday, August 17, 2012 12:08:41 PM UTC-5, dkw wrote:
>
> Howdy: 
>
> I need some help please to get hiera configuration data derived 
> from YAML, thru puppet.  I have studied Internet search results and 
> puppet documentation on create_resources and custom defines but 
> need a little help along.  I can print out the YAML from variables, 
> arrays, and, finally, hashes too from a puppet manifest. 
>
> One thing that is stumping me is how to access from the custom 
> define only the YAML element of server-a which is I believe is an 
> object of an array of hashes as I have the YAML laid out.   
>
> When I run this on client host server-a against the manifest this prints 
> out in the log: 
>
> Aug 17 12:59:09 puppet puppet-master[67407]: 
> (Scope(Sshd_lookup[server-a])) setting sshd_type:  local 
> Aug 17 12:59:09 puppet puppet-master[67407]: 
> (Scope(Sshd_lookup[server-b])) setting sshd_type:  local 
> Aug 17 12:59:09 puppet puppet-master[67407]: 
> (Scope(Sshd_lookup[server-c])) setting sshd_type:  local 
> Aug 17 12:59:09 puppet puppet-master[67407]: 
> (Scope(Sshd_lookup[server-d])) setting sshd_type:  local 
>
> I want it to print out just server-a's value.  How do I do that? 
>


Your focus on what is printed to the log is a bit confusing.  To the extent 
that you are using the log output to track what Puppet is doing it's fine, 
but if your main objective is to extract data from YAML then there are far, 
*far* less convoluted ways to go about it.

 

> Also, interestingly, it printed out each of the server names (keys?) 
> in the hash but the value of the server-a's sshd_auth entry. 
>


Not that interesting, really.  Puppet is just doing what you told it to 
do.  See below.

 

>
> My YAML, puppet manifest and error follow. 
>
> # cat common.yaml 
> --- 
> searchdomain    : 'example.com' 
> ssh_auth        : ldap 
> servers         : 
>   server-a       : 
>                         sshd_auth: "local" 
>                         ClientAliveInterval: "nil" 
>                         ClientAliveCountMax: "nil" 
>   server-b       : 
>                         sshd_auth: "local" 
>                         ClientAliveInterval: "nil" 
>                         ClientAliveCountMax: "nil" 
>   server-c       : 
>                         sshd_auth: "ldap" 
>                         ClientAliveInterval: "nil" 
>                         ClientAliveCountMax: "nil" 
>   server-d       : 
>                         sshd_auth: "ldap" 
>                         ClientAliveInterval: "10" 
>                         ClientAliveCountMax: "3" 
>
>
[...]
 

>
> # cat Inuit.pp 
>     class user { 
>         $sshd_hash = hiera(servers) 
>         create_resources('sshd_lookup', $sshd_hash) 
>

In answer to your first question, about declaring only an sshd_lookup 
resource for server-a, you apparently have a key misunderstanding about 
create_resources().  That function creates one resource of the specified 
type for *each* top-level key in the provided hash.  The keys are used as 
the resource titles, and the values are hashes of parameter key/value pairs 
for the corresponding resource instance.

If you only want an sshd_lookup resource for server-a, then either you must 
feed it a hash containing only an entry for server-a, or else you must 
declare the sshd_lookup in the conventional way.  For example, instead of 
the create_resources() call above, use:

        $server_a_params = $sshd_hash['server-a']
        sshd_lookup { 'server-a':
          sshd_auth => $server_a_params['sshd_auth'],
          ClientAliveInterval => $server_a_params['ClientAliveInterval'],
          ClientAliveCountMax => $server_a_params['ClientAliveCountMax']
        }

Alternatively, you could construct a single-entry hash of hashes of the 
correct form for create_resources(); I leave that as an exercise.
 

>
>     } 
>
>    define sshd_lookup ( $sshd_auth, $ClientAliveInterval, 
> $ClientAliveCountMax, 
> $server_role, $location ) { 
>
>         $data = hiera_hash('servers') 
>         $sshd_type = $data[$hostname]['sshd_auth'] 
>

There, you are looking up an entry in the hash by the $hostname of the 
client for which you are compiling the catalog.  For any given node, that 
will result in the same piece of data for every sshd_lookup instance.

If you want the value appropriate for the current resource instance then 
you can either add $sshd_type to the parameter list (since you are 
otherwise just re-reading the same data that you passed to 
create_resources()), or else use $name or $title (they are equivalent in 
this context) to look up the desired entry in the outer hash.  ($name and 
$title in a type definition refer to the title of the resource instance).

 

>
>         notice ("setting sshd_type:  $sshd_type" ) 
>
>     } 
>
>
Does that help?


John

 

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/puppet-users/-/5Iak2tlXMq8J.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to