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

Using Facter to describe a node

Facter is a separate utility upon which Puppet depends. It is the system used by Puppet to gather information about the target system (node); facter calls the nuggets of information facts. You may run facter from the command line to obtain real-time information from the system.

How to do it...

  1. Use facter to find the current uptime of the system, the uptime fact:
    t@cookbook ~$ facter uptime
    0:12 hours
  2. Compare this with the output of the Linux uptime command:
    t@cookbook ~$ uptime
     01:18:52 up 12 min,  1 user,  load average: 0.00, 0.00, 0.00

How it works...

When facter is installed (as a dependency for puppet), several fact definitions are installed by default. You can reference each of these facts by name from the command line.

There's more...

Running facter without any arguments causes facter to print all the facts known about the system. We will see in later chapters that facter can be extended with your own custom facts. All facts are available for you to use as variables; variables are discussed in the next section.

Variables

Variables in Puppet are marked with a dollar sign ($) character. When using variables within a manifest, it is preferred to enclose the variable within braces "${myvariable}" instead of "$myvariable". All of the facts from facter can be referenced as top scope variables (we will discuss scope in the next section). For example, the fully qualified domain name (FQDN) of the node may be referenced by "${::fqdn}". Variables can only contain alphabetic characters, numerals, and the underscore character (_). As a matter of style, variables should start with an alphabetic character. Never use dashes in variable names.

Scope

In the variable example explained in the There's more… section, the fully qualified domain name was referred to as ${::fqdn} rather than ${fqdn}; the double colons are how Puppet differentiates scope. The highest level scope, top scope or global, is referred to by two colons (::) at the beginning of a variable identifier. To reduce namespace collisions, always use fully scoped variable identifiers in your manifests. For a Unix user, think of top scope variables as the / (root) level. You can refer to variables using the double colon syntax similar to how you would refer to a directory by its full path. For the developer, you can think of top scope variables as global variables; however, unlike global variables, you must always refer to them with the double colon notation to guarantee that a local variable isn't obscuring the top scope variable.

主站蜘蛛池模板: 西吉县| 梅州市| 河池市| 宿迁市| 云南省| 高安市| 曲水县| 延庆县| 襄樊市| 龙山县| 资阳市| 保靖县| 荆门市| 汕尾市| 禹州市| 凤阳县| 遂溪县| 仙游县| 新竹县| 库车县| 晋中市| 邮箱| 阳春市| 开化县| 阿尔山市| 城步| 北碚区| 邵东县| 宁都县| 安图县| 轮台县| 盐源县| 化州市| 理塘县| 扎鲁特旗| 延长县| 武宣县| 大同县| 剑川县| 惠水县| 富阳市|