Is there any example to collect IPs of other nodes to generate a hash to be used in mysql_grant

100 views
Skip to first unread message

Pan Luo

unread,
Dec 19, 2013, 12:55:47 AM12/19/13
to puppet...@googlegroups.com
Hi there,

I'm trying to setup the permissions on mysql database with multiple web servers using puppet-mysql module. I would like to collect all IPs of the web servers and run grant on the database server.

It seems exported resources might help. The only way I can think of right now is to export the file resources on each web node with IP as the content and collect them on the db node. Then I have to load those file content using a custom function. Then generate a hash from them that will be sent to mysql::server grants variable. 

Is there a easier way to do it? Thanks.

Erik Dalén

unread,
Dec 19, 2013, 12:54:37 PM12/19/13
to puppet...@googlegroups.com
If you use puppetdb you can use my puppetdbquery module: http://forge.puppetlabs.com/dalen/puppetdbquery

You will get it as a array of IP addresses though. But should be easier to go from there at least. If you use the future parser it is fairly trivial to convert that to a hash, in the old parser such conversion requires a little more trickery, possibly with some of the stdlib functions.


--
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 view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/bfe2880e-0f5c-4f6d-b65b-9e832f4f9510%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Erik Dalén

Pan Luo

unread,
Dec 19, 2013, 11:52:34 PM12/19/13
to puppet...@googlegroups.com
Hi Erik,

Thanks. I'm using your module right now and was able to get all IPs of the web servers into an array. I'm struggling to convert them into a hash. I'm using puppet 3.3.2, so I suppose it's future parser? Could you give me some light? 

The array I got is something like this: [ip1, ip2]
The hash I would like to be convert to is:
{ ip1 => { attr1 => value1, attr2 => value2}, ip2  => { attr1 => value1, attr2 => value2} }
Ideally if there is any function can merge an array and hash, e.g. merge( [ip1, ip2], { attr1 => value1, attr2 => value2}) to get above value.

Thanks!

Cheers,
Pan

Pan Luo

unread,
Dec 20, 2013, 6:46:09 AM12/20/13
to puppet...@googlegroups.com
Never mind. Got it working with future parser. Here is the reference http://docs.puppetlabs.com/puppet/3/reference/experiments_lambdas.html, might help other people.
Reply all
Reply to author
Forward
0 new messages