Defined Type: autofs::mapping
- Defined in:
- manifests/mapping.pp
Summary
Defined type to manage a single filesystem mapping in a single map file.Overview
When ensured ‘present’, a autofs::mapfile resource managing the overall target map file must also be present in the catalog. This resource implements Autofs’s ‘sun’ map format, which is the default.
It is not supported to declare multiple autofs::mappings with the same key, targetting the same map file, and ensured ‘present’.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'manifests/mapping.pp', line 62
define autofs::mapping (
Stdlib::Absolutepath $mapfile,
String[1] $key,
Variant[String[1], Array[String[1]]] $fs,
Enum['present', 'absent'] $ensure = 'present',
Optional[Autofs::Options] $options = undef,
Integer $order = 10,
) {
unless $ensure == 'absent' {
$formatted_key = if $key =~ /[[:blank:]"]/ {
String($key, '%#p')
} else {
$key
}
# Format the options string, relying to some extent on the
# $options parameter, if specified, to indeed match the
# Autofs::Options data type
if ($options =~ Undef) or ($options =~ Array[Any,0,0]) { # an empty array
$formatted_options = ''
} else {
$prelim_options = $options ? {
Array => join($options, ','), # a non-empty array
String => $options,
default => fail('Unexpected value for parameter $options')
}
$formatted_options = $prelim_options ? {
# even though the user *shouldn't* provide the hyphen, we accommodate
# them doing so. But only at the head of the option list, not
# internally.
/\A-/ => $prelim_options,
default => "-${prelim_options}",
}
}
$formatted_fs = [$fs].flatten.map |$value| { if $value =~ /[[:blank:]"]/ { String($value, '%#p') } else { $value } }.join(' ')
# Declare an appropriate fragment of the target map file
if $formatted_key == '+' {
$content = "${formatted_key}${formatted_fs}\n"
} else {
$content = "${formatted_key}\t${formatted_options}\t${formatted_fs}\n"
}
concat::fragment { "autofs::mapping/${title}":
target => $mapfile,
content => $content,
order => $order,
}
}
}
|