Defined Type: labstore::nfs_mount

Defined in:
modules/labstore/manifests/nfs_mount.pp

Overview

Parameters:

  • mount_path (Any)
  • mount_name (Any)
  • ensure (Any) (defaults to: 'present')
  • project (Any) (defaults to: undef)
  • share_path (Any) (defaults to: undef)
  • server (Any) (defaults to: undef)
  • options (Any) (defaults to: [])
  • block_timeout (Any) (defaults to: 180)
  • lookupcache (Any) (defaults to: 'none')
  • nfs_version (Any) (defaults to: '4')


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
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
# File 'modules/labstore/manifests/nfs_mount.pp', line 33

define labstore::nfs_mount(
    $mount_path,
    $mount_name,
    $ensure = 'present',
    $project = undef,
    $share_path = undef,
    $server = undef,
    $options = [],
    $block_timeout = 180,
    $lookupcache='none',
    $nfs_version = '4',
)
    {

    include ::labstore::traffic_shaping

    $set_opts = ["vers=${nfs_version}",
                'bg',
                'intr',
                'sec=sys',
                'proto=tcp',
                'noatime',
                "lookupcache=${lookupcache}",
                'nofsc',
        ]

    $final_options = flatten([$set_opts,$options])

    if !defined(File['/data']) {
        file { '/data':
            ensure => directory,
            owner  => 'root',
            group  => 'root',
            mode   => '0755',
        }
    }

    if !defined(File['/mnt/nfs']) {
        file { '/mnt/nfs':
            ensure => directory,
            owner  => 'root',
            group  => 'root',
            mode   => '0755',
        }
    }

    if !defined(File['/public']) {
        file { '/public':
            ensure => directory,
            owner  => 'root',
            group  => 'root',
            mode   => '0755',
        }
    }

    if !defined(File['/usr/local/sbin/nfs-mount-manager']) {
        file { '/usr/local/sbin/nfs-mount-manager':
            ensure => present,
            owner  => 'root',
            group  => 'root',
            mode   => '0655',
            source => 'puppet:///modules/labstore/nfs-mount-manager',
        }
    }

    if ($ensure == 'absent') and mount_nfs_volume($project, $mount_name) {

        exec { "cleanup-${mount_path}":
            command   => "/usr/local/sbin/nfs-mount-manager umount ${mount_path}",
            onlyif    => "/usr/local/sbin/nfs-mount-manager check ${mount_path}",
            logoutput => true,
            require   => File['/usr/local/sbin/nfs-mount-manager'],
        }

        mount { $mount_path:
            ensure  => absent,
            require => Exec["cleanup-${mount_path}"],
            notify  => Exec["remove-${mount_path}"],
        }

        exec { "remove-${mount_path}":
            command     => "/usr/bin/timeout -k 5s 10s /bin/rm -rf ${mount_path}",
            refreshonly => true,
            logoutput   => true,
        }
    }

    if ($ensure == 'present') and mount_nfs_volume($project, $mount_name) {

        # 'present' is meant to manage only the status of entries in /etc/fstab
        # a notable exception to this is in the case of an entry managed as 'present'
        # puppet will attempt to remount that entry when options change /but/ only
        # if it is already mounted by forces outside of puppet.
        #
        # remount in general with NFS mounts is suspect as remount does not apply to
        # NFS specific configuration options and will fail on first run and then
        # be ignored until reboot where actual application occurs
        #
        # It is best practice to plan on a reboot in case of option changs or to
        # shuffle the NFS share access point via sym link and a new mount
        mount { $mount_path:
            ensure   => present,
            atboot   => true,
            fstype   => 'nfs',
            options  => join($final_options,','),
            device   => "${server}:${share_path}",
            require  => File['/usr/local/sbin/nfs-mount-manager'],
            remounts => false,
        }

        # Via exec to gracefully handle the frozen mount case where
        # Puppet will normally get stuck and freeze raising load and effectively
        # failing to run
        exec { "create-${mount_path}":
            command   => "/usr/bin/timeout -k 5s 20s /bin/mkdir -p ${mount_path}",
            unless    => "/usr/bin/timeout -k 5s 60s /usr/bin/test -d ${mount_path}",
            logoutput => true,
            require   => Mount[$mount_path],
        }

        exec { "ensure-nfs-${name}":
            command   => "/usr/local/sbin/nfs-mount-manager mount ${mount_path}",
            unless    => "/usr/local/sbin/nfs-mount-manager check ${mount_path}",
            logoutput => true,
            require   => Exec["create-${mount_path}"],
        }
    }

    if !defined(File['/etc/modprobe.d/nfs-no-idmap.conf']) {
        # While the default on kernels >= 3.3 is to have idmap disabled,
        # doing so explicitly does no harm and ensures it is everywhere.
        file { '/etc/modprobe.d/nfs-no-idmap.conf':
            ensure  => present,
            owner   => 'root',
            group   => 'root',
            mode    => '0444',
            content => "options nfs nfs4_disable_idmapping=1\n",
        }
    }
}