Luke Alford
2013-Oct-11 15:26 UTC
[Puppet Users] best practices for reusing ruby functions across custom providers
Hello puppet users, I have recently started dabbling in custom types and providers in order to solve some problems at work. I now find myself needing to have 2 custom providers that leverage a common function to fetch data from a web service and I very much do not want to have 2 copies of this function in my code base. I''d like to hear how others have addressed this kind of problem, and I''m certainly amenable to alternatives if there''s a better way than the types/providers. Here is what I''m trying to do and the constraints I cannot currently get around. 1) I am dynamically configuring nginx virtual hosts and adding lines to /etc/hosts for internal routing (cloud hosted boxes all have external ip''s and I need the various names we support to resolve to internal ip''s of the load balancer) 2) The data I need for this configuration (fqdn''s, certs, and keys) cannot be determined on the puppet master because the data source is a web service (delivers a json array) I install and configure and must be running on the node before I can query it. I already have the custom nginx provider written and working to configure the virtual hosts, but I also need the fqdn''s available from the same web service and I would like to reuse the function that fetches and parses the json from the web service. This second custom provider will be responsible for adding the appropriate lines to /etc/hosts to handle my internal routing problem. Questions: 1) Is there a good way to have an arbitrary ruby module and function that I can require in both of my providers? I''m reasonably good with ruby, but we''re not a ruby shop and I''d rather not have to get into packaging and managing gems for the purpose of sharing a 20 line function in 2 places. 2) Is there a way for custom providers to return data to a manifest? I''d rather use the file_line resource to handle my /etc/hosts needs, but I don''t know of a means of returning data from a resource declaration (which would be my existing custom type using the nginx provider) that I could use in another resource. 3) Is there a way I can pass arguments to an executable fact? I don''t know of one, but I suppose I could set environments variables (i.e. things like the web service host, port, user, password, etc...) provided that executable facts run each time they are referenced in a manifest? Thanks for any input. -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.