Skip to content

Instantly share code, notes, and snippets.

@rockpapergoat
Created September 5, 2014 15:32
Show Gist options
  • Save rockpapergoat/f89c0e5384578b46d95f to your computer and use it in GitHub Desktop.
Save rockpapergoat/f89c0e5384578b46d95f to your computer and use it in GitHub Desktop.
puppet defined type + hiera hash data
define samba::config($includeconf = '', $log_level = '2') {
include samba
if $::operatingsystemrelease =~ /^6/ {
$smb_config='smb.conf_el6.erb'
}
elsif $::operatingsystemrelease =~ /^5/ {
$smb_config='smb.conf_el6.erb'
}
file { '/etc/samba/smb.conf':
content => template("samba/${smb_config}"),
owner => root,
group => root,
mode => '0664',
require => Class['samba::install'],
}
}
define samba::share (
$name,
$path="/srv/export/${name}/share_root",
$writeable='yes',
$create_mask='0770',
$dir_mask='0770',
$hosts_allow='',
$hosts_deny='',
$template='samba/smb_share.conf.erb',
$max_connections='',
$force_create_mode='',
$force_dir_mode='',
$security_mode='',
$blocking_locks='yes',
$msdfs_proxy_path='',
$ensure='present'
) {
# Defines a samba server, with one share, bound to RC AD.
# include samba::config
file { "/etc/samba/smb_${name}.conf":
ensure => $ensure,
content => template($template),
owner => root,
group => root,
mode => '0664',
notify => Class['samba::service'],
require => Class['samba::install'],
}
---
smb_config:
- one
- two
- three
smb_shares:
one:
name: one
two:
name: two
three:
name: three
class profile::storage {
# more details are omitted above. this is the relevant bit.
# add smb_shares hash to hiera for given host
# this bit will create the shares
$smb_shares = hiera('smb_shares')
if ($smb_shares) {
$share_names = $smb_shares['name']
unless (is_hash($smb_shares)) { fail("${smb_shares} is not a valid hash")}
create_resources('samba::share',$smb_shares)
}
$smb_config = hiera_array('smb_config')
if ($smb_config) {
include ::samba
unless (is_array($smb_config)) { fail("${smb_config} is not a valid array")}
ensure_resource('samba::config',[ ::hostname ], { includeconf => $smb_config})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment