Hello! In my puppet configuration I need to get some data from database. Ie.: I''ve got information about my all hosts in db - thier name, mac addresses, ip addresses, what to backup from this host etc. For now it''s just .xml file, but it could be sql db, or ldap directory. Then, using this small "database", I want to generate configuration using puppet - ie.: static mappings for mac=>ip for dhcp server, entries in dns server, proper configuration of backup client and server etc. And my question is: how to you think I should do it in puppet? You now - the best possible way of course :) For now I''m doing something like this: For dhcp and dns I use dnsmasq. So I''ve got module with template hosts.erb: <% require "#{config_dir}/tools/bbox.rb" -%> <% devs=BBOX::Devices.new "#{global_networks_path}/#{lan_dns_domain}" -%> <% devs.get_hosts.each do |host| -%> <%= host[''ip''] %> <%= host[''name''] %>.<%= lan_dns_domain %> <%= host [''name''] %> <% end -%> and dnsmasq.conf.erb: <% require "#{config_dir}/tools/bbox.rb" -%> <% devs=BBOX::Devices.new "#{global_networks_path}/#{lan_dns_domain}" -%> domain-needed domain=<%= lan_dns_domain %> server=/hq.local/<%= global_master_dns_ip %> local=/<%= lan_dns_domain %>/ user=dnsmasq <% unless bind_lan_interfaces_only_real == "no" -%> <% lan_interfaces.each do |interface| -%> interface=<%= interface %> <% end -%> <% end -%> addn-hosts=/etc/hosts.dnsmasq expand-hosts domain=<%= lan_dns_domain %> dhcp-range=<%= lan_subnet_range[0] %>,<%= lan_subnet_range[1] %>,1h <% devs.get_dhcp_static_hosts.each do |host| -%> dhcp-host=<%= host[''ip''] %>,<%= host[''mac''] %> <% end -%> dhcp-authoritative So, what do you think? --- Grzegorz Marszałek graf0@post.pl
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Grzegorz Marszałek wrote:> And my question is: how to you think I should do it in puppet? You > now - the best possible way of course :) >It''s not quite what you''ve described but I think you''re on the path to external/LDAP nodes see: http://reductivelabs.com/trac/puppet/wiki/ExternalNodes http://reductivelabs.com/trac/puppet/wiki/LdapNodes Regards James Turnbull - -- Author of: - - Pulling Strings with Puppet (http://www.amazon.com/gp/product/1590599780/) - - Pro Nagios 2.0 (http://www.amazon.com/gp/product/1590596099/) - - Hardening Linux (http://www.amazon.com/gp/product/1590594444/) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFHYQoO9hTGvAxC30ARAmBTAJ9oz9zKf6ExLstZwVfV6O5kCzNQ2ACcDJRq tuQe9CK/a0Mh30EJdoW1+cU=KHoW -----END PGP SIGNATURE-----
Grzegorz Marszałek
2007-Dec-13 10:49 UTC
Re: access to databases in puppet - best practice?
On 2007-12-13, at 11:31, James Turnbull wrote:> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Grzegorz Marszałek wrote: >> And my question is: how to you think I should do it in puppet? You >> now - the best possible way of course :) >> > > It''s not quite what you''ve described but I think you''re on the path to > external/LDAP nodes see: > > http://reductivelabs.com/trac/puppet/wiki/ExternalNodes > http://reductivelabs.com/trac/puppet/wiki/LdapNodes > >Well, it seems so :) Thanks for the links - I''ve just glanced over them, looks promising. But my question is still valid - how do you extract data from some database and put it in config files that need that data? Using ruby in erb templates? Or maybe creating custom functions/facts? --- Grzegorz Marszałek graf0@post.pl
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Grzegorz Marszałek wrote:> On 2007-12-13, at 11:31, James Turnbull wrote: > >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA1 >> >> Grzegorz Marszałek wrote: >>> And my question is: how to you think I should do it in puppet? You >>> now - the best possible way of course :) >>> >> It''s not quite what you''ve described but I think you''re on the path to >> external/LDAP nodes see: >> >> http://reductivelabs.com/trac/puppet/wiki/ExternalNodes >> http://reductivelabs.com/trac/puppet/wiki/LdapNodes >> >> > Well, it seems so :) Thanks for the links - I''ve just glanced over > them, looks promising. > > But my question is still valid - how do you extract data from some > database and put it in config files that need that data? Using ruby > in erb templates? Or maybe creating custom functions/facts?You can set variables in both external nodes and LDAP that are available to be used in Puppet - including in templates. For example, all attributes assigned to an LDAP node are available as variables much like Facter facts are. Regards James Turnbull - -- Author of: - - Pulling Strings with Puppet (http://www.amazon.com/gp/product/1590599780/) - - Pro Nagios 2.0 (http://www.amazon.com/gp/product/1590596099/) - - Hardening Linux (http://www.amazon.com/gp/product/1590594444/) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFHYSG59hTGvAxC30ARAl9GAJ0VEqBfpSUfR8kRQQI7XrwCzdPyBwCcCrpe NR98p2Kgb9fISB1Vhy3eNok=N4/y -----END PGP SIGNATURE-----
On Dec 13, 2007, at 4:49 AM, Grzegorz Marszałek wrote:> But my question is still valid - how do you extract data from some > database and put it in config files that need that data? Using ruby > in erb templates? Or maybe creating custom functions/facts?The general answer is yes -- Ruby in erb templates, or using external nodes like James says. -- I object to doing things that computers can do. --Olin Shivers --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users