Puppet Class: tftp::server
- Defined in:
- manifests/server.pp
Overview
Class: t:server
Simple class to ensure the tftpd server package is installed
Parameters
- address
-
IP address to bind the daemon process to. default: 0.0.0.0:69
- ensure
-
Used to control the install and configuration or the clean up and unstinall of the tftpd server. default: present
- create
-
Allow new files to be created. By default, tftpd will only allow upload of files that already exist. Files are created with default permissions allowing anyone to read or write them, unless the permissive or umask options are specified. default: false
- listen
-
Run the server in standalone (listen) mode, rather than run from inetd. In listen mode, the timeout option is ignored, and the address option can be used to specify a specific local address or port to listen to. default: true
- permissive
-
Perform no additional permissions checks above the normal system-provided access controls. When set to false, files and directories in tftproot must be world-readable. default: true
- secure
-
Change root directory on startup. This means the remote host does not need to pass along the directory as part of the transfer, and may add security. When secure is true, exactly one tftproot directory should be specified. The use of this option is recommended for security as well as compatibility with some boot ROMs which cannot be easily made to include a directory name in its request. default: true
- timeout
-
When run from inetd this specifies how long, in seconds, to wait for a second connection before terminating the server. inetd will then respawn the server when another request comes in. default: 900 (15 minutes)
- tftproot
-
The directory that tftp content will be served from.
- umask
-
Sets the umask for newly created files to the specified value. default: 377 (owner read-only)
- verbosity
-
Set the logging verbosity value. default: 3
Variables
- defaults_config_file
-
Full path to the defaults file used when starting the tftp daemon
- group
-
Group ID to use for file and directory ownership
- rc2file
-
Full path to the rc2.d file used to test if the tftp service is enabled
- server_package
-
Name of the tftp server package
- service_restart_command
-
Command used to restart the tftp service
- service_start_command
-
Command used to start the tftp service
- service_status_command
-
Command used to get the status of the tftp service
- service_stop_command
-
Command used to stop the tftp service
- mapfile
-
Name of the mapfile
- user
-
User ID to use for file and directory ownership
Examples
class { 'tftp::server':
ensure => 'present',
address => '0.0.0.0:69',
create => true,
listen => true,
permissive => true,
secure => true,
umask => '007',
verbosity => 3,
tftproot => '/srv/tftp',
}
Supported Operating Systems
* CentOS
* Debian
* Fedora
* RedHat
* OpenSUSE
* Ubuntu
Authors
Bennett Samowich <bennett@foolean.org>
Copyright
Copyright (c) 2013 Foolean.org
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
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 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
# File 'manifests/server.pp', line 136
class tftp::server (
$address = '0.0.0.0:69',
$create = false,
$ensure = 'present',
$listen = true,
$permissive = true,
$secure = true,
$timeout = '900',
$tftproot = '/srv/tftp',
$umask = '377',
$verbosity = 3,
)
{
# Set the user for file ownership
$user = $::operatingsystem ? {
'centos' => 'tftp',
'debian' => 'tftp',
'fedora' => 'tftp',
'redhat' => 'tftp',
'opensuse' => 'tftp',
'ubuntu' => 'tftp',
default => 'root',
}
# Set the group for file ownership
$group = $::operatingsystem ? {
'centos' => 'tftp',
'debian' => 'tftp',
'fedora' => 'tftp',
'freebsd' => 'wheel',
'openbsd' => 'wheel',
'redhat' => 'tftp',
'opensuse' => 'tftp',
'ubuntu' => 'tftp',
default => 'root',
}
# Set the name of the tftp package to install
$server_package = $::operatingsystem ? {
'centos' => 'tftp-server',
'debian' => 'tftpd-hpa',
'fedora' => 'tftp-server',
'redhat' => 'tftp-server',
'opensuse' => 'tftp',
'ubuntu' => 'tftpd-hpa',
default => '',
}
# Set the name of the daemon defaults file
$defaults_config_file = $::operatingsystem ? {
'centos' => '/etc/sysconfig/tftpd-hpa',
'debian' => '/etc/default/tftpd-hpa',
'fedora' => '/etc/sysconfig/tftpd-hpa',
'redhat' => '/etc/sysconfig/tftpd-hpa',
'opensus' => '/etc/sysconfig/tftpd-hpa',
'ubuntu' => '/etc/default/tftpd-hpa',
default => false,
}
# Set the name of the init script
$service_init_script = $::operatingsystem ? {
'centos' => '/etc/init.d/tftpd-hpa',
'debian' => '/etc/init.d/tftpd-hpa',
'fedora' => '/etc/init.d/tftpd-hpa',
'redhat' => '/etc/init.d/tftpd-hpa',
'opensus' => '/etc/init.d/tftpd-hpa',
'ubuntu' => '/etc/init.d/tftpd-hpa',
default => false,
}
# Set the name of the init script template
$service_init_script_template = $::operatingsystem ? {
'centos' => '/etc/init.d/tftpd-hpa.rh',
'debian' => '/etc/init.d/tftpd-hpa.deb',
'fedora' => '/etc/init.d/tftpd-hpa.rh',
'redhat' => '/etc/init.d/tftpd-hpa.rh',
'opensuse' => '/etc/init.d/tftpd-hpa.suse',
'ubuntu' => '/etc/init.d/tftpd-hpa.deb',
default => false,
}
# Service status command
$service_status_command = $::operatingsystem ? {
default => '/etc/init.d/tftpd-hpa status',
}
# Service start command
$service_start_command = $::operatingsystem ? {
'ubuntu' => 'service tftpd-hpa start',
default => '/etc/init.d/tftpd-hpa start',
}
# Service stop command
$service_stop_command = $::operatingsystem ? {
'ubuntu' => 'service tftpd-hpa stop',
default => '/etc/init.d/tftpd-hpa stop',
}
# Service restart command
$service_restart_command = $::operatingsystem ? {
'ubuntu' => 'service tftpd-hpa restart',
default => '/etc/init.d/tftpd-hpa restart',
}
# Path to the rc2.d file
$rc2file = $::operatingsystem ? {
'debian' => '/etc/rc2.d/K01tftpd-hpa',
'ubuntu' => '/etc/rc2.d/K01tftpd-hpa',
default => '',
}
# Set the name of the mapfile to use
$mapfile = 'remap'
# Fail if we aren't configured for this operating system
if ( ! $server_package ) {
fail( "Unknown OS '${::operatingsystem}', unable to select packages" )
}
case $ensure {
'present': {
# Install the package
if ( ! defined( Package[$server_package] )) {
package { $server_package:
ensure => 'latest',
}
}
# Ensure the daemon group exists
group { $group:
ensure => 'present',
require => Package[$server_package],
}
# Ensure the daemon user exists
user { $user:
ensure => 'present',
comment => 'tftp daemon',
gid => $group,
home => $tftproot,
shell => '/bin/false',
require => Group[$group],
}
# Configure the default file
if ( $defaults_config_file ) {
file { $defaults_config_file:
mode => '0444',
owner => 'root',
group => 'root',
# lint:ignore:80chars
content => template( "${module_name}/${defaults_config_file}" ),
# lint:endignore
notify => Service['tftp-service'],
require => Package[$server_package]
}
}
# Make sure the tftproot exists
if ( $create ) {
$tftproot_mode = '0600'
} else {
$tftproot_mode = '0400'
}
file { $tftproot:
ensure => 'directory',
owner => $user,
group => $group,
mode => $tftproot_mode,
recurse => true,
require => [
Package[$server_package],
User[$user],
Group[$group],
],
}
# Copy in the init script
file { $service_init_script:
ensure => 'present',
owner => 'root',
group => 'root',
mode => '0755',
content => inline_template(
file (
# lint:ignore:80chars
"${settings::modulepath}/${module_name}/templates/${service_init_script_template}"
# lint:endignore
)
),
require => Package[$server_package],
}
# Copy in the mapfile
file { "${tftproot}/${mapfile}":
ensure => 'present',
owner => $user,
group => $group,
mode => '0400',
content => inline_template(
file (
# lint:ignore:80chars
"${settings::modulepath}/${module_name}/templates/${tftproot}/${mapfile}",
"${settings::modulepath}/../private/${::fqdn}/${tftproot}/${mapfile}",
"${settings::vardir}/private/${::fqdn}/${tftproot}/${mapfile}"
# lint:endignore
)
),
require => [
File[$tftproot],
Package[$server_package],
User[$user],
Group[$group],
],
}
# The package enables inetd, which we typically don't want.
# Nevertheless, we'll use the listen parameter to determine
# the desired state of the daemon and inetd.
if ( $listen ) {
# We'll start the daemon if we're not running inetd
$service_state = 'running'
case $::operatingsystem {
'centos','fedora','opensuse','redhat': {
exec { 'configure-tftpd-inetd':
path => [ '/bin', '/usr/bin/', '/sbin' ],
command => '/sbin/chkconfig tftp off',
# lint:ignore:80chars
unless => [ 'test `chkconfig --list | grep -c "tftp:.*off"` -eq 1' ],
# lint:endignore
require => Package[$server_package],
}
}
'debian', 'ubuntu': {
exec { 'configure-tftpd-inetd':
path => [ '/usr/bin/', '/usr/sbin' ],
command => '/usr/sbin/update-inetd --disable tftp',
# lint:ignore:80chars
onlyif => [ '/usr/bin/test -f /etc/inetd.conf && /usr/bin/test -f /usr/sbin/update-inetd' ],
# lint:endignore
require => Package[$server_package],
}
}
default: {
# lint:ignore:80chars
fail("Module ${module_name} is not supported on ${::operatingsystem}")
# lint:endignore
}
}
} else {
# We'll stop the daemon if we're running inetd
$service_state = 'stopped'
case $::operatingsystem {
'centos','fedora','opensuse','redhat': {
exec { 'configure-tftpd-inetd':
path => [ '/bin', '/usr/bin/', '/sbin' ],
command => '/sbin/chkconfig tftp on',
# lint:ignore:80chars
unless => [ 'test `chkconfig --list | grep -c "tftp:.*on"` -eq 1' ],
# lint:endignore
require => Package[$server_package],
}
}
'debian', 'ubuntu': {
exec { 'configure-tftpd-inetd':
path => [ '/usr/bin/', '/usr/sbin' ],
command => '/usr/sbin/update-inetd --enable tftp',
# lint:ignore:80chars
onlyif => [ '/usr/bin/test -f /etc/inetd.conf && /usr/bin/test -f /usr/sbin/update-inetd' ],
# lint:endignore
require => Package[$server_package],
}
}
default: {
# lint:ignore:80chars
fail("Module ${module_name} is not supported on ${::operatingsystem}")
# lint:endignore
}
}
}
# Reload the service if the configuration changed
service { 'tftp-service':
ensure => $service_state,
name => 'tftpd-hpa',
start => $service_start_command,
stop => $service_stop_command,
status => $service_status_command,
require => [
Package[$server_package],
Exec['configure-tftpd-inetd'],
File[$defaults_config_file],
File[$tftproot],
File[$service_init_script],
User[$user],
Group[$group],
],
}
}
'absent': {
# Stop the service
service { 'tftp-service':
ensure => 'stopped',
enable => false,
name => 'tftpd-hpa',
start => $service_start_command,
stop => $service_stop_command,
status => $service_status_command,
}
# Remove the defautlts file
file { $defaults_config_file:
ensure => 'absent',
before => Package[$server_package],
require => Service['tftp-service'],
}
# Remove the init file
file { $service_init_script:
ensure => 'absent',
before => File[$tftproot],
require => Service['tftp-service'],
}
# Remove the tftproot
file { $tftproot:
ensure => 'absent',
force => true,
before => Package[$server_package],
require => Service['tftp-service'],
}
# Remove the package
if ( ! defined( Package[$server_package] )) {
package { $server_package:
ensure => 'purged',
require => Service['tftp-service'],
}
}
# Remove the daemon user
user { $user:
ensure => 'absent',
require => Package[$server_package],
}
# Remove the daemon group
group { $group:
ensure => 'absent',
require => [
Package[$server_package],
User[$user],
],
}
}
default: {
fail( 'ensure must be "absent" or "present"' )
}
}
}
|