木偶:如何使用Puppet 3.0模板中的MySQL表中的数据?

我有一些数据的真实来源是在MySQL数据库中,数据的大小预计会在几千行的范围内(在最坏的情况下),我想用puppet来configuration文件一些具有这些数据的服务器(大部分是迭代通过模板中的这些行)。

我目前正在使用Puppet 3.0.x,而且我不能改变MySQL将成为这些数据的权威来源的事实。 请注意,数据来自外部,而不是来自木偶或受pipe节点。

那里有什么可能的方法? 你会推荐哪一个?

外部节点分类器在这里有用吗?

我的“最后的手段”是定期将表格转储到YAML文件中,然后通过Hiera读取到Puppet模板,或者直接将表格转储到一个或多个预先格式化的文本文件中以准备复制到节点。

关于系统用户有一个关于SF的未解答的问题,但根本问题可能类似于我 – 他试图从MySQL获取数据。

我走得更远,有一个MySQL数据库是所有服务器数据的权威(这实际上是一个Django的应用程序)。 以下是我如何整合他们:

节点定义

有两种可能性。 我们目前使用一个生成的清单,这是从site.pp包含如下条目:

node "avrdb.prod.example.com" { $sdb_status="live" $sdb_db_type="slave" $sdb_db_version="mysql_55" $sdb_os="co56" include "s_db::avrdb" 

}

但是很快,我们需要把这个切换到ENC,因为木偶不再支持这个了。 ENC已经被写入并使用几乎相同的模板。

服务器数据

一些食谱,如我们的DNS主配方,需要额外的服务器数据。 就像你build议的那样,这是在模板中完成的。 下面是一个这样的模板的例子:named.conf需要知道所有的二级域名服务器。 它只是使用MySQL的gem来到数据库。 数据库结构当然是无关的,但一个完整的例子通常是好的:)

 <% require 'rubygems' require 'mysql' dbh = Mysql.real_connect('serverdb.prod.example.com', 'user', 'pass', 'serverdb') int_slaves = dbh.query("SELECT ip_address, name FROM network_vip WHERE name LIKE 'idns%' ORDER BY name") int_hosts = dbh.query("SELECT i.ip_address, a.name FROM servers_interface as i LEFT JOIN servers_asset as a ON i.asset_id=a.id WHERE a.name regexp '^idns-' and i.name='eth0'"); ext_slaves = dbh.query("SELECT ip_address, name FROM network_vip WHERE name LIKE 'edns%' ORDER BY name") ext_hosts = dbh.query("SELECT i.ip_address, a.name FROM servers_interface as i LEFT JOIN servers_asset as a ON i.asset_id=a.id WHERE a.name regexp '^edns-*' and i.name='eth0'"); %> options { directory "/var/named"; dump-file "/var/named/data/cache_dump.db"; statistics-file "/var/named/data/named_stats.txt"; allow-recursion { none; }; allow-transfer { any; }; allow-query { any; }; // default for transfers-in and transfers-out is 10 transfers-in 128; transfers-out 128; // default for transfers-per-ns is 2 transfers-per-ns 8; // serial-query-rate on a master has undocumented side-effects // of notifying slaves much faster for many zones serial-query-rate 4096; // resolvers or authoritatives also-notify { // Internal slaves <% int_slaves.each{|slave| -%> // <%= slave[1] %> <%= slave[0] %>; <% } int_slaves.data_seek(0) -%> // Internal dns hosts // Needed as we move all the boxes over to HA, where they // query from eth0, not vip <% int_hosts.each{|slave| -%> // <%= slave[1] %> <%= slave[0] %>; <% } int_hosts.data_seek(0) -%> // External slaves <% ext_slaves.each{|slave| -%> // <%= slave[1] %> <%= slave[0] %>; <% } -%> <% ext_hosts.each{|slave| -%> // <%= slave[1] %> <%= slave[0] %>; <% } ext_hosts.data_seek(0) -%> }; }; include "/etc/rndc.key"; // logging logging { channel default_file { file "/var/log/named/named.log" versions 10 size 100m; print-time yes; print-category yes; }; channel security_file { file "/var/log/named/security.log" versions 10 size 100m; print-time yes; print-category yes; }; channel query_file { file "/var/log/named/query.log" versions 10 size 100m; print-time yes; print-category yes; }; channel debug_default { file "/var/log/named/debug.log" versions 10 size 100m; print-time yes; print-category yes; }; category general { default_file; default_debug; }; category security { security_file; }; category default { default_file; }; category queries { query_file; }; category edns-disabled { null; }; }; statistics-channels { inet 127.0.0.1 port 8080; }; // Do not put any zone declarations here unless they differ between views // Put zones with data common to all views in commonzones.conf // This view goes to all the internal nameservers view "internal" { match-clients { // Internal slaves <% int_slaves.each{|slave| -%> // <%= slave[1] %> <%= slave[0] %>; <% } -%> // Internal ds hosts // Safety catch in case they request an AXFR on their eth0 ip <% int_hosts.each{|slave| -%> // <%= slave[1] %> <%= slave[0] %>; <% } -%> }; zone "example.com" IN { type master; file "master/example.com-internal.zone"; }; // This path relative to chroot include "/etc/commonzones.conf"; include "/etc/zones.rfc1918"; }; // This view goes to everyone else view "others" { match-clients { any; }; // Special zones that differ between views zone "example.com" IN { type master; file "master/example.com-external.zone"; }; // This path relative to chroot include "/etc/commonzones.conf"; include "/etc/zones.rfc1918"; }; 

你也可以使用hiera-mysql后端。 如果你看到这个后端的源代码,你可以看到很容易创build一个新的,或者定制这个。 使用像这样的hiera,将使你的模板/清单代码更清洁,比使用丹尼斯build议的方法(它也可以很好地工作)