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 60d8f25 commit df2302d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
23 changes: 13 additions & 10 deletions manifests/plugin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
$manage_config = false,
$config_filename = undef,
$config_content = undef,
$create_user = true,
) {

$plugin = "${name}.hpi"
Expand Down Expand Up @@ -48,18 +49,20 @@

}

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

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

Expand Down
10 changes: 10 additions & 0 deletions spec/defines/jenkins_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,14 @@
it { should contain_exec('download-myplug').with(:environment => ["http_proxy=proxy.company.com:8080", "https_proxy=proxy.company.com:8080"]) }
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 df2302d

Please sign in to comment.