4 ms·
The original example is actually kind of bad and doesn't demonstrate puppet's abstraction facilities. You can define a custom resource, for example "system_fil
by Goladus 16y ago
The original example is actually kind of bad and doesn't demonstrate puppet's abstraction facilities.
You can define a custom resource, for example "system_file" that provides a default "root:root, mask 444" permissions such that you just have to define a source and destination for every file, overriding the default permissions when you want.
define system_file($mode = 444, $owner = root, $group = root, $content = '', $source = '', $ensure = 'present') {
file { $name:
owner => $owner,
group => $group,
mode => $mode,
ensure => $ensure
}
if $source != '' { File[$name] { source => $source } }
if $content != '' { File[$name] { content => $content } }
}
So in the article's example, it would look like this:
system_file { "/etc/ntp.conf":
source => "puppet:///ntpd/ntp.conf",
require => Package["ntp"]
}
Or even
system_file { "/etc/ntp.conf":
source => "$configfiles/ntpd/ntp.conf",
require => Package["ntp"]
}
Where $configfiles might be the puppet server or some other location. One of the things you get with puppet is access to any of the local host properties that can be discovered with facter, so you can dynamically configure something like a source file.
- uggedal 16y agoOr you could override the default file resource attributes in sites.pp: File { owner => root, group => root, mode => 644, } Then you could override that again in individual file resources. If you need several file resources with the same attributes you can override them within the scope of a class: class postgresql { File { owner => "postgres", group => "postgres", mode => 640, } $pgsql_root = "/etc/postgresql/8.4/main" file { "$pgsql_root/postgresql.conf": content => template("postgresql/postgresql.conf.erb"), require => Package["postgresql"], } file { "$pgsql_root/pg_hba.conf": content => template("postgresql/pg_hba.conf.erb"), require => Package["postgresql"], } }