Skip to content
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
20 changes: 20 additions & 0 deletions manifests/account.pp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@
} else {
$_hash = $hash
}

# if you're giving a user's primary group a custom GID, you need to create
# it before you create the user. the puppet user type assumes the GID
# you're giving it for user's primary group already exists. in the case
# where you don't specify the GID, puppet just selects the next available
# GID.
#
# in the case where we're deleting the user, puppet will delete the user's
# primary group automatically, regardless of what the GID is set to. but
# if you try to delete the user's primary group before deleting the user,
# you'll get an error about how you "cannot remove the primary group of
# user blah"
if $ensure != absent {
ensure_resource(
group,
$user,
{gid => $_hash[gid]}
)
}

ensure_resource(
user,
$user,
Expand Down
21 changes: 21 additions & 0 deletions spec/defines/accounts__account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class { 'accounts':
'matt' => {
'comment' => 'Matt M.',
'uid' => 1009,
'gid' => 6666,
},
'brad' => {
'comment' => 'Brad K.',
Expand Down Expand Up @@ -181,6 +182,26 @@ class { 'accounts':
})}
end

context 'when user and custom gid' do
let(:title) { 'matt' }
it { is_expected.to compile.with_all_deps }
it { is_expected.to have_user_resource_count(1) }
it { is_expected.to contain_group('matt').with({
:name => 'matt',
:gid => 6666,
})}
it { is_expected.to contain_user('matt').with({
:name => 'matt',
:ensure => 'present',
:comment => 'Matt M.',
:groups => [],
:home => '/home/matt',
:managehome => true,
:uid => 1009,
:gid => 6666,
})}
end

context 'when user but no key' do
let(:title) { 'matt' }
it { is_expected.to compile.with_all_deps }
Expand Down