Having fixed the yaml...
glusterfs_volumes:
gfsvol01:
master_node: gfs01.us1.xxx.com
transport: tcp
replicas: 0
nodes:
- name: gfs01.us1.xxx.com
bricks:
- /var/bricks/b1
- name: gfs02.us1.xxx.com
bricks:
- /var/bricks/b2
- name: gfs03.us1.xxx.com
bricks:
- /var/bricks/b3
The issue is now.... how do I iterate over the nodes? They are no
longer an array. They are an array of hashes, which puppet doesn't
want to iterate over.
Doug.
On Tue, Aug 28, 2012 at 2:44 PM, jcbollinger <[email protected]> wrote:
>
>
> On Tuesday, August 28, 2012 2:55:20 PM UTC-5, Douglas wrote:
>>
>> Boy... accessing hashes in puppet is downright painful.
>>
>> I have this in a yaml file...
>>
>> glusterfs_volumes:
>> gfsvol01:
>> master_node: gfs01.us1.xxx.com
>> transport: tcp
>> replicas: 0
>> nodes:
>> - gfs01.us1.xxx.com
>> hostname: gfs01
>> state: mounted
>> - gfs02.us1.xxx.com
>> hostname: gfs02
>> state: unmounted
>> - gfs03.us1.xxx.com
>> hostname: gfs03
>> state: mounted
>>
>> I'm loading it with:
>>
>> $config = hiera('glusterfs_volumes')
>> $nodes = $config['gfsvol01']['nodes']
>> ... etc
>>
>> Works fine. I'm also calling a definition like this:
>>
>> glusterfs::add_bricks {
>> [$nodes]:
>> master_node => "$master_node",
>> brick_store => "$brick_store",
>> volume_name => "$name",
>> require => Glusterfs::Add_peers[$nodes];
>> }
>>
>> The question is, how do I access the hostname and state keys inside each
>> node?
>>
>> The following (inside add_bricks):
>>
>> $node = $name['hostname']
>> notice ("DEBUG nodes=$name")
>> notice ("DEBUG NODE=$node")
>>
>> yields, for each call to add_bricks:
>>
>> DEBUG nodes=statemountedgfs01.us1.xxx.com hostnamegfs01
>> DEBUG NODE=
>>
>> I can see the hash in $name... I just can't access the 'state' or
>> 'hostname' keys, which are obviously there.
>>
>> How...?
>
>
> Resource names are strings. If you try to use a hash as a resource name
> then it will be flattened.
>
> Generally speaking, you have several options: you could load the hash into a
> class variable, and have your definitions access it from there. You could
> also pass it as a parameter to your definition. You could even have the
> definition load it (again) via hiera. Sometimes the create_resources()
> function is convenient for unpacking a hash of hashes.
>
> I'm afraid I cannot recommend any specifics to you, however, because your
> YAML is not valid (according to http://yaml-online-parser.appspot.com/ and
> my own eyes), so I don't know what the data structure is supposed to be. It
> looks like something based on create_resources() might work out nicely for
> you, but I can't be sure.
>
>
> 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/-/cS8_5qGpd8wJ.
> 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.
--
Regards,
Douglas Garstang
http://www.linkedin.com/in/garstang
Email: [email protected]
Cell: +1-805-340-5627
--
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.