Skip to content

Commit

Permalink
switch rspec tests to hiera 5
Browse files Browse the repository at this point in the history
  • Loading branch information
deric committed Mar 20, 2019
1 parent 1599c53 commit eddbdd7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ $ facter -y > my_node.yml

### Without Hiera

Using Hiera is optional, you can configure accounts directly from Puppet code:
Using Hiera is optional (though prefered option), you can configure accounts directly from Puppet code:


```puppet
Expand Down
26 changes: 17 additions & 9 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,39 @@
class accounts(
Boolean $manage_users = true,
Boolean $manage_groups = true,
Hash $users = {},
Hash $groups = {},
Hash $user_defaults = lookup('accounts::user_defaults', Hash, {'strategy' => 'deep'}, {}),
Hash $options = lookup('accounts::config', Hash, {'strategy' => 'deep'}, {}),
Boolean $use_lookup = true,
Hash $users = {},
Hash $groups = {},
Hash $user_defaults = {},
Hash $options = {},
Boolean $use_lookup = true,
) inherits ::accounts::params {

# currently used mainly in tests to turn-off hiera backends
# puppet should automatically resolve class parameters from hiera
if $use_lookup {
$users_h = lookup('accounts::users', Hash, {'strategy' => 'deep'}, {})
$groups_h = lookup('accounts::groups', Hash, {'strategy' => 'deep'}, {})
# merge behavior (3rd argument )is intentionally ommited, so that it could
# be overidden in hiera configs
$users_h = lookup('accounts::users', Hash, undef, {})
$groups_h = lookup('accounts::groups', Hash, undef, {})
$user_defaults_h = lookup('accounts::user_defaults', Hash, undef, {})
$options_h = lookup('accounts::config', Hash, undef, {})
} else {
$users_h = {}
$groups_h = {}
$user_defaults_h = {}
$options_h = {}
}

$_users = merge($users, $users_h)
anchor { 'accounts::users_created': }

class{'::accounts::config':
options => $options,
options => merge($options, $options_h),
before => Anchor['accounts::users_created'],
}

if $manage_users {
$udef = merge($user_defaults, {
$udef = merge($user_defaults, $user_defaults_h, {
home_permissions => $::accounts::params::home_permissions,
require => Anchor['accounts::users_created'],
})
Expand Down
4 changes: 4 additions & 0 deletions spec/fixtures/hiera/default.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
---
lookup_options:
"^accounts::(.*)":
merge:
strategy: deep
accounts::users:
myuser:
uid: 1000
Expand Down
19 changes: 10 additions & 9 deletions spec/fixtures/hiera/hiera.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
---
:backends:
- yaml
:hierarchy:
- '%{::clientcert}'
- test
- default
:yaml:
:datadir: './spec/fixtures/hiera'
:merge_behavior: deep
version: 5
defaults:
datadir: '.' # This path is relative to hiera.yaml's directory.
data_hash: yaml_data # Use the built-in YAML backend.

hierarchy:
- name: "test"
path: "test.yaml"
- name: "default"
path: "default.yaml"

0 comments on commit eddbdd7

Please sign in to comment.