learning puppet 2--Variables and Facts

发布时间:2017-3-27 6:48:17 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"learning puppet 2--Variables and Facts",主要涉及到learning puppet 2--Variables and Facts方面的内容,对于learning puppet 2--Variables and Facts感兴趣的同学可以参考一下。

1)Variables $variables always start with a dollar sign. You assign to variables with the = operator.Variables can hold strings, numbers, booleans, arrays, hashes, and the special undef value. See the data types chapter of the Puppet reference manual for more information.If you’ve never assigned a variable, you can actually still use it — its value will be undef.You can use variables as the value for any resource attribute, or as the title of a resource.You can also interpolate variables inside double-quoted strings. To distinguish a variable from the surrounding text, you can wrap its name in curly braces. ("This is the ${variable} name.") This isn’t mandatory, but it is recommended. Every variable has two names: A short local nameA long fully-qualified name Fully qualified variables look like $scope::variable. Top scope variables are the same, but their scope is nameless. (For example: $::top_scope_variable.) If you reference a variable with its short name and it isn't present in the local scope, Puppet will also check the global top scope; this means you can almost always refer to global variables with just their short names. You can see more about this in the scope chapter of the Puppet reference manual: scope in Puppet Enterprise 2.x and Puppet 2.7, scope in Puppet 3You can only assign the same variable once in a given scope. In this way, they’re more like constants from other programming languages. 2)Facts Puppet has a bunch of built-in, pre-assigned variables that you can use. Check it out: # /root/examples/motd.pp file {'motd': ensure => file, path => '/etc/motd', mode => 0644, content => "This Learning Puppet VM's IP address is ${ipaddress}", }output: # cat /etc/motd This Learning Puppet VM's IP address is $ipaddress is one of "facts". Puppet uses a tool called Facter, which discovers some system information, normalizes it into a set of variables, and passes them off to Puppet. Puppet’s compiler then has access to those facts when it's reading a manifest. See here for a list of all of the "core" facts built into Facter. Most of them are always available to Puppet, although some of them are only present on certain system types.You can see what Facter knows about a given system by running facter at the command line.You can also see all of the facts for any node in your Puppet Enterprise deployment by browsing to that node’s page in the console and scrolling down to the inventory information.You can also add new custom facts to Puppet; see the custom facts guide for more information.