Skip to content
This repository has been archived by the owner on Jun 11, 2019. It is now read-only.

Adding nfs::export resource to manage /etc/exports file … #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,34 @@ For detailed info about the logic and usage patterns of Example42 modules check
'client_options' is a passthrough to the [mount type options attribute] (https://docs.puppetlabs.com/references/latest/type.html#mount-attribute-options).
If the mountpoint directory does not exist it will be created along with any parent directories that don't exist, essentially 'mkdir -p $mountpoint'.

* Exporting NFS shares (server only)

nfs::export { '/var/log':
hosts => [{ # Hosts must be wrapped in [] even if it is a single entry
'host' => '*', # Host can be '*', IP, IP w/ netmask, or hostname
'options' => 'ro,fsid=0' # Host specific nfs options
}],
order => 10 # Optional, order to arrange export entries. Defaults to 100
}

* Another example with multiple access control entries

nfs::export { '/opt/tomcat/webapps':
hosts => [
{
'host' => 'host.example.com',
'options' => 'rw'
},
{
'host' => '192.168.56.0/24',
'options' => 'rw,sync'
},
{
'host' => '*',
'options' => 'ro,fsid=0'
}
]
}

## USAGE - Overrides and Customizations
* Use custom sources for main config file
Expand Down
28 changes: 28 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,34 @@ For detailed info about the logic and usage patterns of Example42 modules check
'client_options' is a passthrough to the {mount type options attribute}[https://docs.puppetlabs.com/references/latest/type.html#mount-attribute-options].
If the mountpoint directory does not exist it will be created along with any parent directories that don't exist, essentially 'mkdir -p $mountpoint'.

* Exporting NFS shares (server only)

nfs::export { '/var/log':
hosts => [{ # Hosts must be wrapped in [] even if it is a single entry
'host' => '*', # Host can be '*', IP, IP w/ netmask, or hostname
'options' => 'ro,fsid=0' # Host specific nfs options
}],
order => 10 # Optional, order to arrange export entries. Defaults to 100
}

* Another example with multiple access control entries

nfs::export { '/opt/tomcat/webapps':
hosts => [
{
'host' => 'host.example.com',
'options' => 'rw'
},
{
'host' => '192.168.56.0/24',
'options' => 'rw,sync'
},
{
'host' => '*',
'options' => 'ro,fsid=0'
}
]
}

== USAGE - Overrides and Customizations
* Use custom sources for main config file
Expand Down
27 changes: 27 additions & 0 deletions manifests/export.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This resource manages an individual export rule in /etc/exports
define nfs::export(
$mount_point = $name,
$hosts,
$order = '100',
) {
include nfs
include nfs::params

if $nfs::manage_config_file == false {
warn('nfs::manage_config_file has been disabled. This resource is now unused!')
} else {
validate_absolute_path($mount_point)
validate_array($hosts)
# FIXME: Add validation of hash values for host and options
# host: one of '*', IP, IP w/ netmask, or a hostname
# options: any of 'ro','rw','sync',wdelay...
validate_numeric($order)

# Create an exports fragment
concat::fragment { "nfs_cfg_${name}":
target => $nfs::config_file,
content => template($nfs::template),
order => $order,
}
}
}
6 changes: 1 addition & 5 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@
$config_file_owner = params_lookup( 'config_file_owner' ),
$config_file_group = params_lookup( 'config_file_group' ),
$config_file_init = params_lookup( 'config_file_init' ),
$manage_config_file = params_lookup( 'manage_config_file' ),
$pid_file = params_lookup( 'pid_file' ),
$data_dir = params_lookup( 'data_dir' ),
$log_dir = params_lookup( 'log_dir' ),
Expand Down Expand Up @@ -327,11 +328,6 @@
default => $nfs::source,
}

$manage_file_content = $nfs::template ? {
'' => undef,
default => template($nfs::template),
}

include nfs::client

if $nfs::mode == 'server' {
Expand Down
4 changes: 3 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,16 @@
$source = ''
$source_dir = ''
$source_dir_purge = false
$template = ''
$manage_config_file = true
$template = 'nfs/export.erb'
$options = ''
$service_autorestart = true
$version = 'present'
$absent = false
$disable = false
$disableboot = false
$mounts = {}
$aggregate = false # controls concatination of the nfs_cfg file

### General module variables that can have a site or per module default
$monitor = false
Expand Down
45 changes: 32 additions & 13 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,40 @@
noop => $nfs::noops,
}

file { 'nfs.conf':
ensure => $nfs::manage_file,
path => $nfs::config_file,
mode => $nfs::config_file_mode,
owner => $nfs::config_file_owner,
group => $nfs::config_file_group,
require => Package[$nfs::package],
notify => $nfs::manage_service_autorestart,
source => $nfs::manage_file_source,
content => $nfs::manage_file_content,
replace => $nfs::manage_file_replace,
audit => $nfs::manage_audit,
noop => $nfs::noops,
if $nfs::manage_config_file
and $nfs::aggregate {
concat { $nfs::config_file:
ensure => $nfs::manage_file,
mode => $nfs::config_file_mode,
owner => $nfs::config_file_owner,
group => $nfs::config_file_group,
require => Package[$nfs::package],
notify => $nfs::manage_service_autorestart,
warn => true,
order => numeric,
replace => $nfs::manage_file_replace,
audit => $nfs::manage_audit,
noop => $nfs::noops,
}
}
else {
file { $nfs::config_file:
ensure => $nfs::manage_file,
path => $nfs::config_file,
mode => $nfs::config_file_mode,
owner => $nfs::config_file_owner,
group => $nfs::config_file_group,
require => Package[$nfs::package],
notify => $nfs::manage_service_autorestart,
source => $nfs::manage_file_source,
content => $nfs::manage_file_content,
replace => $nfs::manage_file_replace,
audit => $nfs::manage_audit,
noop => $nfs::noops,
}
}


# The whole nfs configuration directory can be recursively overriden
if $nfs::source_dir
and $nfs::config_dir != '' {
Expand Down
1 change: 1 addition & 0 deletions templates/export.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= "#{mount_point}" %><% hosts.each { |host| %><%= " #{host['host']}" %><% unless host['options'].nil? || host['options'].empty? %><%= "(#{host['options']})" %><% end %><% } %>