- Puppet 5 Essentials(Third Edition)
- Martin Alfke Felix Frank
- 647字
- 2021-07-02 18:22:27
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.
puppet apply -e 'notify { "I am ${::networking['fqdn']} and have ${::processors['count]} CPUs": }'
- Dynamics 365 for Finance and Operations Development Cookbook(Fourth Edition)
- DB2 V9權(quán)威指南
- Java EE 6 企業(yè)級(jí)應(yīng)用開發(fā)教程
- Spring Cloud Alibaba微服務(wù)架構(gòu)設(shè)計(jì)與開發(fā)實(shí)戰(zhàn)
- Mastering Adobe Captivate 2017(Fourth Edition)
- Maven Build Customization
- Arduino by Example
- Python高級(jí)編程
- HTML5 and CSS3 Transition,Transformation,and Animation
- 精通網(wǎng)絡(luò)視頻核心開發(fā)技術(shù)
- Hands-On Reinforcement Learning with Python
- ANSYS Fluent 二次開發(fā)指南
- ExtJS高級(jí)程序設(shè)計(jì)
- Mastering C++ Multithreading
- Elasticsearch Essentials