Defined Type: tp::dir
- Defined in:
- manifests/dir.pp
Overview
This define manages whole directories related to the application (app) set in the title. If the vcsrepo parameter is set, the content of the directory is populated from the url defined in the source parameter. If no vcsrepo is used, the directory is manage by the native file resource. The actual path of the managed directory is determined with this logic:
-
If the path parameter is passed, that’s the path used
-
If an absolute dir path is set in the title, then it’s used this path
-
If no path is explicitly set and the title contains only the app name (ex: ‘apache’) then it’s managed its main configuration directory as determined tp’s data/ directory.
- If no path is set and the title is
-
separated (ex: ‘apache::conf’), then
the dir path name is set by the second element set in the title. Common names for dir types are:
- config (default, it refers to the main configuraion directory of the app) - conf (a conf.d style directory where to place configuration fragments) - log (the logs dir, if exists) - data (where application data is stored)
that removes any local file not present on the source directory (Be careful with purge ad force params, they can delete files)
tp::dir { '/data/www/default':
source => 'puppet:///modules/site/apache/role/fe',
purge => true,
force => true,
}
with extra options (must be valid options for the chosen vcsrepo)
tp::dir { '/etc/puppetlabs/code/environments/production':
source => 'https://git.internal/puppet/control-repo',
vcsrepo => git,
vcsrepo_options => {
trust_server_cert => true,
}
}
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'manifests/dir.pp', line 129
define tp::dir (
String[1] $ensure = 'present',
Variant[Undef,String,Array] $source = undef,
Variant[Undef,Boolean,String] $vcsrepo = false,
Hash $vcsrepo_options = {},
String[1] $base_dir = 'config',
Variant[Undef,String] $path = undef,
Variant[Undef,String] $mode = undef,
Variant[Undef,String] $owner = undef,
Variant[Undef,String] $group = undef,
Enum['global','user'] $scope = 'global',
String $path_prefix = '',
Boolean $path_parent_create = false,
Variant[Boolean,String] $config_dir_notify = true,
Variant[Boolean,String] $config_dir_require = true,
Variant[Undef,Boolean] $purge = undef,
Variant[Undef,Boolean] $recurse = undef,
Variant[Undef,Boolean] $force = undef,
Hash $settings_hash = {},
Boolean $debug = false,
String[1] $debug_dir = '/tmp',
String[1] $data_module = 'tinydata',
) {
# Settings evaluation
$title_elements = split ($title, '::')
$app = $title_elements[0]
$dir = $title_elements[1]
# Check if repo or upstream_repo are set in tp::install
if defined_with_params(Tp::Install[$app]) {
$repo = getparam(Tp::Install[$app],'repo')
}
if defined_with_params(Tp::Install[$app]) {
$upstream_repo = getparam(Tp::Install[$app],'upstream_repo')
}
if $title =~ /^\/.*$/ {
# If title is an absolute path do a safe lookup to
# a dummy app
$tp_settings = tp_lookup('test','settings','tinydata','merge')
$title_path = $title
} else {
$tp_settings = tp_lookup($app,'settings',$data_module,'merge')
$title_path = undef
}
$settings = $tp_settings + $settings_hash
$prefix = $scope ? {
'global' => '',
'user' => 'user_',
}
$base_dir_path = $settings["${prefix}${base_dir}_dir_path"]
$real_path = pick($path, $title_path, $base_dir_path)
$manage_path = "${path_prefix}${real_path}"
$manage_mode = pick($mode, $settings[config_dir_mode])
$manage_owner = pick($owner, $settings[config_dir_owner])
$manage_group = pick($group, $settings[config_dir_group])
# Set require if package_name is present and title is not a abs path
if $settings[package_name] and $settings[package_name] != ''
and $title !~ /^\/.*$/ {
$package_ref = "Package[${settings[package_name]}]"
} else {
$package_ref = undef
}
$manage_require = $config_dir_require ? {
'' => undef,
false => undef,
true => $package_ref,
default => $config_dir_require,
}
# Set notify if service_name is present and title is not a abs path
if $settings[service_name] and $settings[package_name] != ''
and $title !~ /^\/.*$/ {
$service_ref = "Service[${settings[service_name]}]"
} else {
$service_ref = undef
}
$manage_notify = $config_dir_notify ? {
'' => undef,
false => undef,
true => $service_ref,
default => $config_dir_notify,
}
$ensure_vcsrepo = $ensure ? {
'directory' => 'present',
default => $ensure,
}
$ensure_dir = tp::ensure2dir($ensure)
# Finally, the resources managed
if $path_parent_create {
$path_parent = dirname($manage_path)
$exec_before = $vcsrepo ? {
undef => File[$manage_path],
default => Vcsrepo[$manage_path],
}
exec { "mkdir for tp::dir ${title}":
command => "/bin/mkdir -p ${path_parent}",
creates => $path_parent,
before => $exec_before,
}
}
if $vcsrepo {
$vcsrepo_defaults = {
ensure => $ensure_vcsrepo,
source => $source,
provider => $vcsrepo,
owner => $manage_owner,
group => $manage_group,
}
vcsrepo { $manage_path:
* => $vcsrepo_defaults + $vcsrepo_options,
}
} else {
$file_params = {
ensure => $ensure_dir,
source => $source,
path => $manage_path,
mode => $manage_mode,
owner => $manage_owner,
group => $manage_group,
require => $manage_require,
notify => $manage_notify,
recurse => $recurse,
purge => $purge,
force => $force,
}
file { $manage_path:
* => $file_params + pick($settings[config_dir_params],{}),
}
}
# Debugging
if $debug == true {
$debug_scope = inline_template('<%= scope.to_hash.reject { |k,v| k.to_s =~ /(uptime.*|path|timestamp|free|.*password.*)/ } %>')
file { "tp_dir_debug_${title}":
ensure => $ensure,
content => $debug_scope,
path => "${debug_dir}/tp_dir_debug_${title}",
}
}
}
|