Skip to content

Commit

Permalink
Make creation of user optional
Browse files Browse the repository at this point in the history
Currently, the creation of jenkins user
and group is protected by if !defined. This
can be extremely annoying in cases where code
is trying to install a competing jenkins user/group.

In my specific case, I'm blocked by this code
leading to duplicate jenkins users (and I need
my definition to be created first). In general,
I thought that these kinds of issue were resolvable
via enusre that classes were including in a certain
order, but I cannot seem to resove it in my specific use
case which involves:
* nested class includes
* serialized user resources from hiera
* create_resources
  • Loading branch information
bodepd committed Jan 14, 2015
1 parent 7e47b62 commit 716fa44
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
26 changes: 14 additions & 12 deletions manifests/plugin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# create this content from a template or any other mean.
#
# update_url = undef
#
#
define jenkins::plugin(
$version = 0,
$manage_config = false,
Expand All @@ -18,6 +18,7 @@
$username = 'jenkins',
$group = 'jenkins',
$enabled = true,
$create_user = true,
) {
include ::jenkins::params

Expand Down Expand Up @@ -65,18 +66,19 @@

}

if (!defined(Group[$group])) {
group { $group :
ensure => present,
require => Package['jenkins'],
if $create_user {
if (!defined(Group[$group])) {
group { $group :
ensure => present,
require => Package['jenkins'],
}
}
}

if (!defined(User[$username])) {
user { $username :
ensure => present,
home => $plugin_parent_dir,
require => Package['jenkins'],
if (!defined(User[$username])) {
user { $username :
ensure => present,
home => $plugin_parent_dir,
require => Package['jenkins'],
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion spec/defines/jenkins_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
it { should contain_exec('download-myplug').with(:environment => ["http_proxy=proxy.company.com:8080", "https_proxy=proxy.company.com:8080"]) }
end


describe 'with a custom update center' do
shared_examples 'execute the right fetch command' do
it 'should wget the plugin' do
Expand Down Expand Up @@ -154,5 +153,14 @@
end
end
end
context 'when not installing users' do
let :params do
{'create_user' => false}
end
it 'should not create user or group' do
should_not contain_group('jenkins')
should_not contain_user('jenkins')
end
end

end

0 comments on commit 716fa44

Please # to comment.