Skip to content

Commit

Permalink
Refactor hiera lookup options to be optional
Browse files Browse the repository at this point in the history
Hiera lookups now use the default automatic lookup
merge options. README has been updated to note how
to perform a Hash or Deep merge from within your
data file using the lookup_options key
  • Loading branch information
David Hollinger committed Sep 12, 2017
1 parent 1830e9a commit 36b81ff
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
22 changes: 22 additions & 0 deletions README.md
Expand Up @@ -111,6 +111,28 @@ autofs::mounts:
order: 01
```

If you need to merge the `autofs::mounts` key from multiple files or hiera lookups, be sure to add the `lookup_options`
key and set the merge behavior for `autofs::mounts` to `merge: hash`

```yaml
lookup_options:
autofs::mounts:
merge: hash
autofs::mounts:
home:
mount: '/home'
mapfile: '/etc/auto.home'
mapcontents:
- '* -user,rw,soft,intr,rsize=32768,wsize=32768,tcp,nfsvers=3,noacl server.example.com:/path/to/home/shares'
options: '--timeout=120'
order: 01
```

For more information about merge behavior see the doc for:

* [Lookup docs](https://docs.puppet.com/puppet/4.7/lookup_quick.html#puppet-lookup:-quick-reference-for-hiera-users)
* [Hiera 5 docs](https://docs.puppet.com/puppet/5.1/hiera_merging.html) if using Puppet >= 4.9

##### Direct Map `/-` arugment

The autofs module also supports the use of the built in autofs `/-` argument used with Direct Maps.
Expand Down
15 changes: 7 additions & 8 deletions manifests/init.pp
Expand Up @@ -74,8 +74,8 @@
# on boot.
#
class autofs (
Optional[Hash] $mounts = undef,
Optional[Hash] $maps = undef,
Hash[String, Hash] $mounts = {},
Hash[String, Hash] $maps = {},
String $package_ensure = 'installed',
Enum[ 'stopped', 'running' ] $service_ensure = 'running',
Boolean $service_enable = true,
Expand All @@ -85,12 +85,11 @@
contain '::autofs::service'
}

if $mounts {
$data = hiera_hash('autofs::mounts', $mounts)
create_resources('autofs::mount', $data)
$mounts.each |String $mount, Hash $attributes| {
autofs::mount { $mount: * => $attributes }
}
if $maps {
$_datamaps = hiera_hash('autofs::maps', $maps)
create_resources('autofs::map',$_datamaps)

$maps.each |String $map, Hash $attributes| {
autofs::map { $map: * => $attributes }
}
}
2 changes: 1 addition & 1 deletion spec/classes/autofs_spec.rb
Expand Up @@ -102,7 +102,7 @@
let(:params) { { mounts: mounts } }

it 'is expected to fail' do
is_expected.to compile.and_raise_error(%r{parameter 'mounts' expects a value of type Undef or Hash})
is_expected.to compile.and_raise_error(%r{parameter 'mounts' expects a Hash value})
end
end
end

0 comments on commit 36b81ff

Please sign in to comment.