Puppet Class: nfs_server

Inherits:
nfs_server::params
Defined in:
manifests/init.pp

Overview

Nfs_server

Support for NFSv4 kernel server on Linux

The main source of configuration is the share_hash variable which is responsible for creating and exporting each shared directory. It has the form:

share_hash => {
    "directory_name" => {
      client => client(share_option1,...,share_optionN) client(share_option1,...,share_optionN),
      owner  => OWNER_OF_SHARE_DIR,
      group  => GROUP_OF_SHARE_DIR,
      mode   => MODE_OF_SHARE_DIR,
    }
  }

Examples:

real-world share_hash

share_hash => {
  "/scratch/foo" => {
    "client" => "192.168.0.10(ro) 192.168.0.11(rw)",
  },
  "/scratch/bar" => {
    "client" => "192.168.*(ro)",
    "owner"  => "foo",
    "group"  => "bar",
    "mode"   => "0755",
  },
  "/scratch/testcase" => {
    "client"     => "*(ro)",
    "manage_dir" => false,
  },

Parameters:

  • package (String) (defaults to: $nfs_server::params::package)

    Name of nfs kernel server package to install

  • manage_package (Boolean) (defaults to: true)

    true to manage the package with Puppet

  • ensure_package (Enum[present,absent]) (defaults to: present)

    State to ensure the package to

  • share_hash (Hash) (defaults to: {})

    Hash of shares to export (see above)

  • default_owner (String) (defaults to: $nfs_server::params::default_owner)

    Default owner of shares (override in hash)

  • default_group (String) (defaults to: $nfs_server::params::default_group)

    Default group of shares (override in hash)

  • default_mode (String) (defaults to: "0770")

    Default mode of shares (override in hash)

  • manage_service (Boolean) (defaults to: true)

    true to manage the service with Puppet

  • service (String) (defaults to: $nfs_server::params::service)

    Name of the nfs service on this system

  • service_ensure (Enum[running,stopped]) (defaults to: running)

    State to ensure the service to (if managed)

  • service_enable (Boolean) (defaults to: true)

    true to start the service on boot

  • exports (String) (defaults to: "/etc/exports")

    location of the exports file (usually /etc/exports)



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
# File 'manifests/init.pp', line 47

class nfs_server(
    String                $package        = $nfs_server::params::package,
    Boolean               $manage_package = true,
    Enum[present,absent]  $ensure_package = present,
    Hash                  $share_hash     = {},
    String                $default_owner  = $nfs_server::params::default_owner,
    String                $default_group  = $nfs_server::params::default_group,
    String                $default_mode   = "0770",
    Boolean               $manage_service = true,
    String                $service        = $nfs_server::params::service,
    Enum[running,stopped] $service_ensure = running,
    Boolean               $service_enable = true,
    String                $exports        = "/etc/exports",
) inherits nfs_server::params {

  if $manage_package {
    package { $package:
      ensure => $ensure_package,
    }
  }

  file { "/etc/exports":
    ensure => file,
    owner  => "root",
    group  => "root",
    mode   => "0644",
  }

  $share_hash.each |$share_dir, $opts| {

    # manage the shared directory with puppet unless we were told not to (it
    # could be a mounted elsewhere)
    if pick($opts["manage_dir"],true) {
      $mode = pick($opts['mode'], $default_mode)
      file { $share_dir:
        ensure => directory,
        owner  => pick($opts['owner'], $default_owner),
        group  => pick($opts['group'], $default_group),
        mode   => $mode,
      }
    }

    # munge the line for /etc/exports
    file_line { "exports_for_${share_dir}":
      ensure => present,
      path   => $exports,
      line   => "${share_dir}\t${opts['client']}",
      match  => "^${share_dir}\t",
      notify => Exec["reload_nfs_exports"],
    }
  }

  if $manage_service {
    $service_require = Service[$service]

    service { $service:
      ensure  => $service_ensure,
      enable  => $service_enable,
      require => Package[$package],
    }
  } else {
    $service_require = undef
  }

  exec { "reload_nfs_exports":
    command     => "exportfs -a",
    path        => ["/usr/sbin", "/sbin"],
    refreshonly => true,
    require     => $service_require,
  }

}