Defined Type: labstore::nfs_mount

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

Overview

Parameters:

  • mount_path (Stdlib::Unixpath)
  • mount_name (String)
  • ensure (Wmflib::Ensure) (defaults to: 'present')
  • options (Array) (defaults to: [])
  • block_timeout (Integer) (defaults to: 180)
  • nfs_version (Pattern[/^4(:?\.[0-2])?$/]) (defaults to: '4')
  • server (Optional[Stdlib::Host]) (defaults to: undef)
  • share_path (Optional[Stdlib::Unixpath]) (defaults to: undef)


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

define labstore::nfs_mount(
    Stdlib::Unixpath           $mount_path,
    String                     $mount_name,
    Wmflib::Ensure             $ensure        = 'present',
    Array                      $options       = [],
    Integer                    $block_timeout = 180,
    Pattern[/^4(:?\.[0-2])?$/] $nfs_version   = '4',
    Optional[Stdlib::Host]     $server        = undef,
    Optional[Stdlib::Unixpath] $share_path    = undef,
){

    ensure_packages(['nfs-common'])

    include labstore::traffic_shaping

    $set_opts = ["vers=${nfs_version}",
                'bg',
                'intr',
                'sec=sys',
                'proto=tcp',
                'noatime',
                'lookupcache=all',
                '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') {

        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') {

        # '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'], Package['nfs-common']],
            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",
        }
    }
}