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

Examining Puppet core resource types

To complete our tour of the basic elements of a manifest, let's take a closer look at the resource types that you have already used, and some of the more important ones that you have not yet encountered and are part of Puppet's base installation.

You probably already have a good feeling for the file type, which will ensure the existence of files and directories, along with their permissions. Pulling a file from a repository (usually, a Puppet module) using the source parameter is also a frequent use case.

For very short files, it is more economical to include the desired content right in the manifest:

file { '/etc/modules':
ensure => file,
content => "# Managed by Puppet!\n\ndrbd\n",
}
The double quotes allow expansion of escape sequences, such as \n.

Another useful capability is managing symbolic links:

file { '/etc/apache2/sites-enabled/001-puppet-lore.org':
ensure => 'link',
target => '../sites-available/puppet-lore.org',
}

You should be aware that the file resource type requires an absolute path and filename. If a relative path is used within the title, then Puppet will produce an error:

file { '../demo.txt':
ensure => file,
}
puppet apply file_error.pp
Notice: Compiled catalog for puppetmaster.demo.example42.com in environment production in 0.09 seconds
Error: Parameter path failed on File[../demo.txt]: File paths must be fully qualified, not '../demo.txt' at /root/file_error.pp:1

The next type that you already know is package, and its typical usage is quite intuitive. Make sure that packages are either installed or removed. A notable use case that you have not yet seen is to use the basic package manager instead of apt or yum/zypper. This is useful if the package is not available from a repository:

package { 'haproxy':
ensure => present,
provider => 'dpkg',
source => '/opt/packages/haproxy-1.5.1_amd64.dpkg',
}

Your mileage usually increases if you make the effort of setting up a simple repository instead, so that the main package manager can be used after all.

Last but not least, there is a service type, the most important attributes of which you already know. It's worth pointing out that it can serve as a simple shortcut in cases where you don't wish to add a fully-fledged init script or something similar. With enough information, the base provider for the service type will manage simple background processes for you:

service { 'count-logins':
provider => 'base',
ensure => 'running',
enable => true,
binary => '/usr/local/bin/cnt-logins',
start => '/usr/local/bin/cnt-logins –daemonize',
has_status => true,
has_restart => true,
subscribe => File['/usr/local/bin/cnt-logins'],
}

Puppet will not only restart the script if it is not running for some reason, but will also restart it whenever the content of the referenced configuration file changes.
This only works if Puppet manages the file content and all changes propagate through Puppet only.

If Puppet changes any other property of the script file (for example, the file mode), that too will lead to a restart of the process.

Let's take a look at some other types you will probably need.

主站蜘蛛池模板: 神木县| 类乌齐县| 虞城县| 曲麻莱县| 龙江县| 厦门市| 洪泽县| 正镶白旗| 大连市| 宾阳县| 札达县| 张掖市| 广宗县| 长岭县| 理塘县| 阳西县| 兴国县| 扶余县| 清水县| 深州市| 搜索| 龙门县| 涞源县| 南溪县| 安图县| 赫章县| 上犹县| 申扎县| 邵阳市| 甘谷县| 昌图县| 莆田市| 东莞市| 东乡族自治县| 兴山县| 塔城市| 邹平县| 岐山县| 武清区| 交城县| 龙海市|