On Aug 22, 2008, at 12:55 PM, Francois Deppierraz wrote:

>
> Adam Jacob wrote:
>
>> If what you are trying to do is eval some puppet code, literally, I'm
>> totally unclear as to what the purpose of that would be.
>
> Yes, I'm trying to eval puppet code.
>
> In fact this eval function is only part of another function I'm trying
> to hack.
>
> The goal is to generate ressources in Puppet from a REST webservice
> returning CSV data.
>
> For example, imagine you have a webservice like that listing all  
> your users:
>
> uid;gecos;password
> francois;Francois Deppierraz;1234
> john;John Doe;5678
>
> Based on that, I want to generate the following ressource  
> *dynamically*.
>
> user {"francois":
>  ensure   => present,
>  gecos    => "Francois Deppierraz",
>  password => "1234",
> }
>
> user {"john":
>  ensure   => present,
>  gecos    => "John Doe",
>  password => "5678",
> }
>
> The current usage of this function is:
>
> class blah {
>  csv_template "http://mydb/users"; "my-user-template.erb"
> }
>
> From there, a ressource is created for each line (except the header)
> using the ERB template.
>
> The only piece I'm missing is how to feed those ressources back into
> Puppet. I hope this makes my use case a bit clearer.

As Adam said, the "right" way to do this right now is to create the  
resources and add them to the parser's resource graph, or -- and more  
preferably -- use ActiveRecord to add them to the db and then use a  
collection to query them out.  See below.

And as Blake and Andrew say, this should get easier as we migrate the  
StoreConfigs stuff to the Indirector interface.

If you are willing to use ActiveRecord, which is the best choice here  
ATM, then just create each of the resources you want in the db, using  
standard ActiveRecord code -- write a simple Ruby script that reads  
that CSV file in and writes the resulting resources to the db.  Make  
sure they're all marked exported, and I recommend storing them as part  
of a fake host instance, so it's easy to remove them when you want.

Then have something like this in your config:

User << | |>>

...which will find all exported users and add them to the catalog.

I did exactly this for a client and it worked really well, but they  
haven't indicated whether the code can be released.

My goal is for the export and collection interface to go through the  
Indirector at some point, which would make it straightforward to add  
whatever kind of backend repository you wanted, but we're likely a  
ways out on that.

-- 
Risk! Risk anything! Care no more for the opinions of others, for those
voices. Do the hardest thing on earth for you. Act for yourself. Face
the truth. -- Katherine Mansfield
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" 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-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to