Ask Your Question
0

Assign MySQL data to array

asked 2015-01-19 08:43:44 -0500

r0cket gravatar image

Hello!

I need set data from MySQL table to my array in general manifest site.pp. Like at it:

site.pp:

$all_users = mysql.select("Select users.name FROM users, Where flag > 10");

define  homes {
 file { "/home/${title}/.test":
  ensure  => present,
  content => $title,
 }
}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
-1

answered 2015-01-19 17:34:36 -0500

cbarbour gravatar image

updated 2015-01-20 19:03:03 -0500

hiera-mysql will do what you want. With Hiera-mysql, you would configure your MySQL database as a hiera backend, and access the data you want using hiera() or lookup() function calls.

Otherwise, it should be relatively trivial to write a custom function call that queries mysql and returns an array or hash.

I have enough programming skills in Ruby, in a BASH or Python. By this writing your own backend for Puppet - not solutions. I find it easier to write analogue Puppet Than backend.

To the best of my knowledge, no one has published a mysql lookup function for Puppet (nothing turned up on the forge, or on Google.)

A custom function is not a backend for Puppet; it's simply an interface that allows you to write Ruby code to handle tasks that aren't possible in the Puppet DSL. Anytime a lookup is performed in the DSL, a function is called. The requested syntax in your original post appears to be a function call as well.

Here's an example of the function call to query CSV files.

https://github.com/ripienaar/puppet-extlookup/blob/master/lib/puppet/parser/functions/extlookup.rb

Your question is already answered here. I did not recommend generate specifically because you requested an array; generate() would produce a string that you would need to split.

As an aside, not liking an answer doesn't make the answer wrong.

edit flag offensive delete link more

Comments

Hiera does not suit me because of the presence of only one type of request, I need a few of these. Hiera also does not have enough full documentation for its use or any complete examples.

r0cket gravatar imager0cket ( 2015-01-20 01:42:20 -0500 )edit

I have enough programming skills in Ruby, in a BASH or Python. By this writing your own backend for Puppet - not solutions. I find it easier to write analogue Puppet Than backend.

r0cket gravatar imager0cket ( 2015-01-20 01:46:06 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-01-19 08:43:44 -0500

Seen: 792 times

Last updated: Jan 20 '15