Skip to content

Add manage_groups parameter #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 15, 2016
Merged
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
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ creation.
Create a local user by providing at a minimum the user name, state, comment,
groups, and initial password:

local_user { 'username':
local_user { 'rnelson':
state => 'present',
comment => 'Real Name',
groups => ['group1', 'group2'],
comment => 'Rob Nelson',
groups => ['rnelson0', 'wheel'],
password => 'encryptedstring',
}

You may also provide the shell, home directory, password max age, the last
change date (YYYY-MM-DD or number of days since Jan 1, 1970), and an array of ssh keys. These values
default to /bin/bash, /home/<username>, 90 days, 0 days, and null, respectively.

local_user { 'username':
local_user { 'rnelson':
state => 'present',
shell => '/bin/bash',
home => '/home/username',
home => '/home/rnelson0',
managehome => true,
comment => 'Real Name',
groups => ['group1', 'group2'],
gid => 'primary_group'
comment => 'Rob Nelson',
groups => ['rnelson0', 'wheel'],
gid => 'rnelson0'
last_change => '2015-01-01',
password => 'encryptedstring',
password_max_age => 90,
Expand All @@ -51,3 +51,9 @@ default to /bin/bash, /home/<username>, 90 days, 0 days, and null, respectively.

Note: The encrypted string is processed via sed using '/' seperators. You MUST
escape any '/' characters.

If the specified groups do not exist and or not created elsewhere in your catalog (or ordered incorrectly), you will receive errors preventing the user from being created.

Error: Could not create user rnelson0: Execution of '/usr/sbin/useradd -c Rob Nelson -g rnelson0 -G wheel -d /home/rnelson0 -s /bin/bash -m rnelson0' returned 6: useradd: group 'rnelson0' does not exist

Set the parameter `manage_groups` to `true` and the groups will be managed and ordered within `local_user`.
9 changes: 9 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# password_max_age => 90,
# last_change => '2015-01-01',
# ssh_authorized_keys => ['ssh-rsa AAAA...123 user@host'],
# manage_groups => true,
# }
#
# === Authors
Expand All @@ -38,6 +39,7 @@
$home = "/home/${name}",
$managehome = true,
$ssh_authorized_keys = [],
$manage_groups = false,
) {
validate_string($name)
validate_string($state)
Expand All @@ -59,6 +61,13 @@
if ($uid) {
validate_integer($uid)
}
if ($manage_groups) {
$managed_groups = [$groups, $gid]
group { $managed_groups:
ensure => present,
before => User[$name],
}
}
user { $name:
ensure => $state,
shell => $shell,
Expand Down
24 changes: 24 additions & 0 deletions spec/defines/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@
:groups => ['group1', 'group2'],
:password_max_age => 90,
}) }
it { is_expected.not_to create_group('rnelson0') }
end

context 'managing groups' do
let (:params) do
{
:state => 'present',
:comment => 'Rob Nelson',
:groups => ['group1', 'group2'],
:password => 'encryptedstring',
:manage_groups => true,
}
end

it { is_expected.to create_user('rnelson0').with({
:comment => 'Rob Nelson',
:groups => ['group1', 'group2'],
}) }
it { is_expected.to create_group('rnelson0') }
it { is_expected.to create_group('group1') }
it { is_expected.to create_group('group2') }
end

context 'using full params' do
Expand All @@ -32,6 +53,7 @@
:password_max_age => 120,
:ssh_authorized_keys => ['ssh-rsa AAAA...zwE1 rsa-key-20141029'],
:uid => 101,
:gid => 'group2',
}
end

Expand All @@ -44,6 +66,7 @@
:uid => 101,
}) }
it { is_expected.to create_local_user__ssh_authorized_keys('ssh-rsa AAAA...zwE1 rsa-key-20141029') }
it { is_expected.not_to create_group('rnelson0') }
end

context 'with a valid date for last_change' do
Expand All @@ -58,6 +81,7 @@
end

it { is_expected.to create_user('rnelson0') }
it { is_expected.not_to create_group('rnelson0') }
end

context 'with an invalid date for last_change' do
Expand Down