JeremyCampbell
2012-Sep-08 15:59 UTC
[Puppet Users] Making a result of custom function available to multiple classes
Hey, I''m using Puppet 2.7.19 with hiera 0.3.0. I have an Openvpn module which has a custom function that queries a mysql db and returns a hash. I also need the hash values in other modules e.g. firewall module. Since the custom function is in the openvpn/lib/puppet/parser/functions folder I believe it is autoloaded and is available from other modules. However, I don''t want to have to call the custom function multiple times as it''s an expensive mysql query. What would be the best way to call the custom function once and make the returned hash available to other modules? Thanks for your time! Cheers, J. -- 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/-/5jQz2SxDxicJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Krzysztof Wilczynski
2012-Sep-08 22:31 UTC
[Puppet Users] Re: Making a result of custom function available to multiple classes
Hi, Since functions run on the Puppet Master side, the simplest solution is to cache the value if its "freshness" is not mandatory i.e. does not change, lets say every 5 minutes? Or, even it will be fine every 24 hours, etc ... Consider this snippet: https://gist.github.com/3680388 Let me know if you have troubles adapting this for your function, I am always keen to help :) KW On Saturday, September 8, 2012 4:59:31 PM UTC+1, JeremyCampbell wrote:> > Hey, > > I''m using Puppet 2.7.19 with hiera 0.3.0. I have an Openvpn module which > has a custom function that queries a mysql db and returns a hash. I also > need the hash values in other modules e.g. firewall module. Since the > custom function is in the openvpn/lib/puppet/parser/functions folder I > believe it is autoloaded and is available from other modules. However, I > don''t want to have to call the custom function multiple times as it''s an > expensive mysql query. What would be the best way to call the custom > function once and make the returned hash available to other modules? > > Thanks for your time! > > Cheers, > J. > >-- 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/-/BCancuZNchMJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
jcbollinger
2012-Sep-10 13:47 UTC
[Puppet Users] Re: Making a result of custom function available to multiple classes
On Saturday, September 8, 2012 5:31:06 PM UTC-5, Krzysztof Wilczynski wrote:> > Hi, > > Since functions run on the Puppet Master side, the simplest solution is to > cache the value if its "freshness" is not mandatory i.e. does not change, > lets say every 5 minutes? Or, even it will be fine every 24 hours, etc ... > > Consider this snippet: https://gist.github.com/3680388 > > Let me know if you have troubles adapting this for your function, I am > always keen to help :) >And one form of caching the result would be to assign it to a class (or global) variable. A class variable make sense to me, as you should have exactly one class responsible for actually running the function and assigning the result anyway. That''s about as simple as you can do, and it would get you one function call per catalog compilation. Caching the result outside of Puppet would allow you to reduce the number of function calls further. 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/-/jdso_mjLjogJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.