files.pp 1.7 KB
Newer Older
Angel L. Mateo's avatar
Angel L. Mateo committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# == Define freeradius::module::files
#
# Create e file module configuration for FreeRADIUS
#
define freeradius::module::files (
  $ensure                     = 'present',
  String $moddir              = "\${modconfdir}/\${.:instance}",
  Optional[String] $key       = undef,
  String $filename            = "\${moddir}/authorize",
  Optional[String] $usersfile = undef,
  String $acctusersfile       = "\${moddir}/accounting",
  String $preproxy_usersfile  = "\${moddir}/pre-proxy",
  Array[Hash] $users          = [],
  Optional[String] $source    = undef,
  Optional[String] $content   = undef,
) {
  $fr_moduleconfigpath = $::freeradius::params::fr_moduleconfigpath
  $fr_group            = $::freeradius::params::fr_group
  $fr_service          = $::freeradius::params::fr_service

  $manage_content = $content ? {
    undef     => template('freeradius/users.erb'),
    default   => $content,
  }

  $manage_dir = $ensure ? {
    'present' => 'directory',
    default   => 'absent',
  }

  if $filename =~ /^\$\{moddir\}\/(.+)$/ {
    $userspath = "${fr_moduleconfigpath}/${name}/${1}"
    $usersdir  = "${fr_moduleconfigpath}/${name}"
  } else {
    $userspath = $filename
    $usersdir  = dirname($filename)
  }

  freeradius::module {$name:
    ensure  => $ensure,
    content => template('freeradius/files.erb'),
  }

  file {$usersdir:
    ensure  => $manage_dir,
    owner   => 'root',
    group   => $fr_group,
    mode    => '0750',
    require => Freeradius::Module[$name],
  }

  file {$userspath:
    ensure  => $ensure,
    owner   => 'root',
    group   => $fr_group,
    mode    => '0640',
    source  => $source,
    content => $manage_content,
    require => File[$usersdir],
    notify  => Service[$fr_service],
  }
}