官术网_书友最值得收藏!

Putting it all together - collecting system information with Facter

Configuration management is quite a dynamic problem. In other words, the systems that need configuration are mostly moving targets. In some situations, system administrators or operators get lucky and work with large quantities of 100 percent uniform hardware and software. In most cases, however, the landscape of servers and other computing nodes is rather heterogeneous, at least in subtle ways. Even in unified networks, there are likely multiple generations of machines or operating systems, with smaller or larger differences required for their respective configurations.

For example, a common task for Puppet is to handle the configuration of system monitoring. Your business logic will likely dictate warning thresholds for gauges such as the system load value. However, those thresholds can rarely be static. On a two-processor virtual machine, a system load of 10 represents a crippling overload, while the same value can be absolutely acceptable for a busy DBMS server that has cutting edge hardware of the largest dimensions.

Another important factor can be software platforms. Your infrastructure might span multiple distributions of Linux or alternate operating systems, such as BSD, Solaris, or Windows, each with different ways of handling certain scenarios. Imagine, for example, that you want Puppet to manage some content from the fstab file. On your rare Solaris system, you would have to make sure that Puppet targets the /etc/vfstab file instead of /etc/fstab.

It is usually not a good idea to interact directly with the fstab file in your manifest. This example will be rounded off in the section concerning providers.

Puppet strives to present you with a unified way of managing all your infrastructure. It therefore needs a means to allow your manifests to adapt to different kinds of circumstances on the agent machines. This includes their operating system, hardware layout, and many other details. Keep in mind that, generally, the manifests have to be compiled on the master machine.

There are several conceivable ways to implement a solution for this particular problem. A direct approach would be to use a language construct that allows the master to send a piece of shell script (or other code) to the agent and receive its output in return.

The following is pseudocode; however, there are no back tick expressions in the Puppet DSL:

if `grep -c ^processor /proc/cpuinfo` > 2 {
$load_warning = 4
}
else {
$load_warning = 2
}

This solution would be powerful but expensive. The master would need to call back to the agent whenever the compilation process encountered such an expression. Writing manifests that were able to cope with such a command returning an error code would be strenuous, and Puppet would likely end up resembling a quirky scripting engine.

Puppet uses a different approach. It relies on a secondary system called Facter, which has the sole purpose of examining the machine on which it is run. It serves a list of well-known variable names and values, all according to the system on which it runs. For example, an actual Puppet manifest that needs to form a condition upon the number of processors on the agent will use this expression:

if $::processors['count'] > 4 { … } 

Facter's variables are called facts, and processors is one such fact. With Facter version 3 or later, most data will be gathered and presented as structured facts (JSON). In the example, we accessed the 'count' element from 'processors' data. The older key-value pairs are still available. The fact values are gathered by the agent and sent to the master, who will use these facts to compile a catalog. All fact names are available in the manifests as variables.

Facts are also available to manifests that are used with puppet apply, of course. You can test this very simply with the following:
puppet apply -e 'notify { "I am ${::networking['fqdn']} and have ${::processors['count]} CPUs": }'
主站蜘蛛池模板: 德清县| 瑞昌市| 准格尔旗| 罗平县| 驻马店市| 白玉县| 商水县| 丰镇市| 且末县| 昆明市| 尉犁县| 商南县| 景宁| 左权县| 西峡县| 娱乐| 息烽县| 江阴市| 垦利县| 顺义区| 江华| 克什克腾旗| 呼伦贝尔市| 慈溪市| 张家界市| 浠水县| 青田县| 湾仔区| 宁陕县| 泸西县| 鄂尔多斯市| 昔阳县| 鄂尔多斯市| 鞍山市| 同心县| 台安县| 垣曲县| 安阳市| 木兰县| 仁寿县| 房产|