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

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": }'
主站蜘蛛池模板: 阳曲县| 于田县| 彩票| 湖北省| 梅州市| 阿荣旗| 类乌齐县| 沙雅县| 新乡市| 沧源| 宁明县| 潜江市| 卢龙县| 长寿区| 淮北市| 合水县| 友谊县| 乐至县| 舒兰市| 綦江县| 永靖县| 江源县| 新密市| 金昌市| 浦江县| 烟台市| 醴陵市| 临高县| 利辛县| 石渠县| 吉木乃县| 乌兰察布市| 祁东县| 合江县| 汉中市| 册亨县| 泸定县| 浠水县| 沾化县| 灌南县| 廊坊市|