Skip to content

Commit

Permalink
Merge pull request #122 from iflowfor8hours/next
Browse files Browse the repository at this point in the history
Add support for disabling ssl verification on slaves
  • Loading branch information
R. Tyler Croy committed Apr 17, 2014
2 parents 1c469fa + b30e9e4 commit 1eb3d13
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 20 deletions.
43 changes: 27 additions & 16 deletions manifests/slave.pp
Expand Up @@ -36,10 +36,13 @@
# [*slave_mode*]
# Defaults to 'normal'. Can be either 'normal' (utilize this slave as much as possible) or 'exclusive' (leave this machine for tied jobs only).
#
# [*disable_ssl_verification*]
# Disable SSL certificate verification on Swarm clients. Not required, but is necessary if you're using a self-signed SSL cert. Defaults to false.
#
# [*labels*]
# Not required. Single string of whitespace-separated list of labels to be assigned for this slave.
#
# [*jave_version*]
# [*java_version*]
# Specified which version of java will be used.
#

Expand All @@ -59,19 +62,20 @@
#
# Copyright 2013 Matthew Barr , but can be used for anything by anyone..
class jenkins::slave (
$masterurl = undef,
$ui_user = undef,
$ui_pass = undef,
$version = $jenkins::params::swarm_version,
$executors = 2,
$manage_slave_user = true,
$slave_user = 'jenkins-slave',
$slave_uid = undef,
$slave_home = '/home/jenkins-slave',
$slave_mode = 'normal',
$labels = undef,
$install_java = $jenkins::params::install_java,
$enable = true
$masterurl = undef,
$ui_user = undef,
$ui_pass = undef,
$version = $jenkins::params::swarm_version,
$executors = 2,
$manage_slave_user = true,
$slave_user = 'jenkins-slave',
$slave_uid = undef,
$slave_home = '/home/jenkins-slave',
$slave_mode = 'normal',
$disable_ssl_verification = false,
$labels = undef,
$install_java = $jenkins::params::install_java,
$enable = true
) inherits jenkins::params {

$client_jar = "swarm-client-${version}-jar-with-dependencies.jar"
Expand All @@ -83,8 +87,15 @@
}
}

#add jenkins slave user if necessary.
#If disable_ssl_verification is set to true
if $disable_ssl_verification {
# disable SSL verification to the init script
$disable_ssl_verification_flag = '-disableSslVerification'
} else {
$disable_ssl_verification_flag = ''
}

#add jenkins slave user if necessary.
if $manage_slave_user and $slave_uid {
user { 'jenkins-slave_user':
ensure => present,
Expand Down Expand Up @@ -160,7 +171,7 @@
require => Package['daemon'],
}

package { 'daemon':
package {'daemon':
ensure => present,
}
}
Expand Down
18 changes: 16 additions & 2 deletions spec/classes/jenkins_slave_spec.rb
Expand Up @@ -12,15 +12,29 @@
it { should contain_user('jenkins-slave_user').with_uid(nil) }
end

describe 'with ssl verification disabled' do
let(:params) { { :disable_ssl_verification => true } }
it { should contain_file('/etc/init.d/jenkins-slave').with_content(/-disableSslVerification/) }
end

describe 'slave_uid' do
let(:params) { { :slave_uid => '123' } }
it { should contain_user('jenkins-slave_user').with_uid(123) }
end
end

describe 'Debian' do
let(:facts) { { :ostype => 'Debian' } }
it { expect { should raise_error(Puppet::Error) } }
let(:facts) { { :osfamily => 'Debian', :lsbdistid => 'debian', :lsbdistcodename => 'natty', :operatingsystem => 'Debian' } }
describe 'default' do
it { should contain_exec('get_swarm_client') }
it { should contain_file('/etc/init.d/jenkins-slave') }
it { should contain_service('jenkins-slave') }
it { should contain_user('jenkins-slave_user').with_uid(nil) }
end
describe 'with ssl verification disabled' do
let(:params) { { :disable_ssl_verification => true } }
it { should contain_file('/etc/default/jenkins-slave').with_content(/-disableSslVerification/) }
end
end

describe 'Unknown' do
Expand Down
2 changes: 1 addition & 1 deletion templates/jenkins-slave-defaults.Debian
Expand Up @@ -43,4 +43,4 @@ EXECUTORS=<%= @executors -%>
CLIENT_NAME=<%= @fqdn -%>


JENKINS_SLAVE_ARGS="<%= @ui_user_flag -%> <%= @ui_pass_flag -%> -name $CLIENT_NAME -executors $EXECUTORS $MASTER_URL"
JENKINS_SLAVE_ARGS="<%= @ui_user_flag -%> <%= @ui_pass_flag -%> -name $CLIENT_NAME <%= @disable_ssl_verification_flag -%> -executors $EXECUTORS $MASTER_URL"
2 changes: 1 addition & 1 deletion templates/jenkins-slave.erb
Expand Up @@ -19,7 +19,7 @@ fi

slave_start() {
echo Starting Jenkins Slave...
$RUNUSER - <%= @slave_user -%> -c 'java -jar <%= @slave_home -%>/<%= @client_jar -%> <%= @ui_user_flag -%> <%= @ui_pass_flag -%> -mode <%= @slave_mode -%> -name <%= @fqdn || @hostname -%> -executors <%= @executors -%> <%= @masterurl_flag -%> <%= @labels_flag -%> &'
$RUNUSER - <%= @slave_user -%> -c 'java -jar <%= @slave_home -%>/<%= @client_jar -%> <%= @ui_user_flag -%> <%= @ui_pass_flag -%> -mode <%= @slave_mode -%> -name <%= @fqdn || @hostname -%> -executors <%= @executors -%> <%= @masterurl_flag -%> <%= @labels_flag -%> <%= @disable_ssl_verification_flag -%> &'
pgrep -f -u <%= @slave_user -%> <%= @client_jar -%> > $PID_FILE
RETVAL=$?
[ $RETVAL -eq 0 ] && touch $LOCK_FILE
Expand Down

0 comments on commit 1eb3d13

Please sign in to comment.