aboutsummaryrefslogtreecommitdiff
path: root/manifests/subsystem/nas/share.pp
blob: 94f8194ed6b7f8d1138396205abd8c203ccfa251 (plain)
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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# Share a folder pubicly using FTP, Samba, NFS, DLNA, etc.
define nodo::subsystem::nas::share(
  $description,
  $folder,
  $owner                = '',
  $group                = '',
  $mode                 = '',
  $dlna_type            = '',
  $nfs_export_target    = '127.0.0.1',
  $nfs_export_options   = 'ro,sync,no_subtree_check',
  $samba_guest_only     = true,
  $samba_guest_ok       = true,
  $samba_force_user     = '',
  $samba_force_group    = '',
  $samba_read_only      = '',
  $samba_writable       = '',
  $samba_create_mask    = '0644',
  $samba_directory_mask = '0755',
  $manage_folder        = true
) {
  #
  # DLNA share
  #
  $dlna = hiera('nodo::role::nas::dlna', false)

  if $dlna == true and $dlna_type != '' {
    minidlna::share { $folder:
      type => $dlna_type ? {
        'all'   => undef,
        default => $dlna_type,
      },
    }
  }

  #
  # Samba share
  #
  $samba = hiera('nodo::role::nas::samba', false)

  if $samba == true {
    samba::server::share { $name:
      comment        => $description,
      path           => $folder,
      guest_only     => $samba_guest_only,
      guest_ok       => $samba_guest_ok,
      force_user     => $samba_force_user ? {
        ''      => undef,
        default => $samba_force_user,
      },
      force_group    => $samba_force_group ? {
        ''      => undef,
        default => $samba_force_group,
      },
      read_only    => $samba_read_only ? {
        ''      => undef,
        default => $samba_read_only,
      },
      writable    => $samba_writable ? {
        ''      => undef,
        default => $samba_writable,
      },
      create_mask    => $samba_create_mask ? {
        ''      => undef,
        default => $samba_create_mask,
      },
      directory_mask    => $samba_directory_mask ? {
        ''      => undef,
        default => $samba_directory_mask,
      },
      browsable      => true,
    }
  }

  #
  # NFS export
  #
  $nfs = hiera('nodo::role::nas::nfs', false)

  if $nfs == true {
    nfs::export { $name:
      export_directory => $folder,
      export_target    => $nfs_export_target,
      export_options   => $nfs_export_options,
    }
  }

  #
  # HTTP and FTP symlinks to media assets
  #
  $http = hiera('nodo::role::nas::http', false)

  if $http == true {
    file { [ "/var/www/data/${name}", "/home/ftp/${name}" ]:
      ensure  => $folder,
      require => File['/var/www/data', '/home/ftp'],
    }
  }

  #
  # Avahi service
  #
  $avahi = hiera('nodo::role::nas::avahi', false)

  if $avahi == true and $nfs == true {
    file { "/etc/avahi/services/nfs-${name}.service":
      ensure => present,
      owner  => root,
      group  => root,
      mode   => '0644',
      source => "puppet:///modules/site_avahi/services/nfs-${name}.service",
      notify => Service['avahi-daemon'],
    }
  }

  # Make sure basic media exist, no matter which disk is attached
  $cache = hiera('nodo::subsystem::media::folders::base', '/var/cache/media')

  if $cache != '' and $manage_folder != false {
    file { [ "${cache}/${name}" ]:
      ensure => directory,
      owner  => $owner ? {
        ''      => undef,
        default => $owner,
      },
      group  => $group ? {
        ''      => undef,
        default => $group,
      },
      mode  => $mode ? {
        ''      => undef,
        default => $mode,
      },
    }
  }
}