Skip to content

Commit

Permalink
Convert variables and if/then logic to Hiera-based yaml files.
Browse files Browse the repository at this point in the history
  • Loading branch information
bschonec committed Jul 13, 2022
1 parent 3707320 commit a2d2ccd
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 38 deletions.
3 changes: 3 additions & 0 deletions data/os/Debian.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---

rsync::server::conf_file: '/etc/rsyncd.conf'
4 changes: 4 additions & 0 deletions data/os/FreeBSD.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---

rsync::server::conf_file: '/usr/local/etc/rsync/rsyncd.conf'
rsync::server::servicename: 'rsyncd'
4 changes: 4 additions & 0 deletions data/os/RedHat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---

rsync::server::conf_file: '/etc/rsyncd.conf'
rsync::server::servicename: 'rsyncd'
4 changes: 4 additions & 0 deletions data/os/RedHat/8.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---

# RHEL8 and newer have a separate package for the rsync daemon.
rsync::server::package_name: rsync-daemon
4 changes: 4 additions & 0 deletions data/os/RedHat/9.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---

# RHEL8 and newer have a separate package for the rsync daemon.
rsync::server::package_name: rsync-daemon
4 changes: 4 additions & 0 deletions data/os/Suse.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---

rsync::server::conf_file: '/etc/rsyncd.conf'
rsync::server::servicename: 'rsyncd'
64 changes: 26 additions & 38 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,22 @@
# class rsync
#
class rsync::server(
$use_xinetd = true,
$address = '0.0.0.0',
$motd_file = 'UNSET',
Boolean $use_xinetd = true,
$address = '0.0.0.0',
$motd_file = 'UNSET',
Variant[Enum['UNSET'], Stdlib::Absolutepath] $pid_file = '/var/run/rsyncd.pid',
$use_chroot = 'yes',
$uid = 'nobody',
$gid = 'nobody',
$modules = {},
$use_chroot = 'yes',
$uid = 'nobody',
$gid = 'nobody',
$modules = {},
Optional[String[1]] $package_name = undef,
String[1] $conf_file = '/etc/rsync.conf',
String[1] $servicename = 'rsync',
Stdlib::Ensure::Service $service_ensure = 'running',
Boolean $service_enable = true,
Boolean $manage_package = $rsync::manage_package,
) inherits rsync {

case $facts['os']['family'] {
'Debian': {
$conf_file = '/etc/rsyncd.conf'
$servicename = 'rsync'
}
'Suse': {
$conf_file = '/etc/rsyncd.conf'
$servicename = 'rsyncd'
}
'RedHat': {
$conf_file = '/etc/rsyncd.conf'
$servicename = 'rsyncd'
}
'FreeBSD': {
$conf_file = '/usr/local/etc/rsync/rsyncd.conf'
$servicename = 'rsyncd'
}
default: {
$conf_file = '/etc/rsync.conf'
$servicename = 'rsync'
}
}

if $use_xinetd {
include xinetd
xinetd::service { 'rsync':
Expand All @@ -50,18 +33,23 @@
require => Package['rsync'],
}
} else {
if ($facts['os']['family'] == 'RedHat') and
(Integer($facts['os']['release']['major']) >= 8) and
($rsync::manage_package) {
package { 'rsync-daemon':
ensure => $rsync::package_ensure,
notify => Service[$servicename],

# Manage the installation of the rsyncd package?
if $manage_package {

# RHEL8 and newer (and their variants) have a separate package for rsyncd daemon. If the $package_name
# variable is defined (the variable is defined in the hiera hierarchy), then install the package.
if $package_name {
package {$package_name:
ensure => $rsync::package_ensure,
notify => Service[$servicename],
}
}
}

service { $servicename:
ensure => running,
enable => true,
ensure => $service_ensure,
enable => $service_enable,
hasstatus => true,
hasrestart => true,
subscribe => Concat[$conf_file],
Expand Down

0 comments on commit a2d2ccd

Please sign in to comment.