Skip to content

Commit

Permalink
initial auto jenkins provisioning
Browse files Browse the repository at this point in the history
  • Loading branch information
George Adams committed Feb 9, 2018
1 parent fe59b83 commit 5939bfb
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.idea/*
ansible/playbooks/*.retry
*.pyc
ansible/host_vars/*
ansible/host_vars
hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
##########################
# adoptopenjdk_variables #
##########################

# jenkins domain
Jenkins_Domain: ci.adoptopenjdk.net
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
##########################
# adoptopenjdk_variables #
##########################

# jenkins domain
Jenkins_Domain: ci-jck.adoptopenjdk.net
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
##########################
# adoptopenjdk_variables #
##########################

# jenkins domain
Jenkins_Domain: ci.adoptopenjdk.net
1 change: 1 addition & 0 deletions ansible/playbooks/AdoptOpenJDK_Unix_Playbook/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Debug
- Common
- Jenkins_User
- Jenkins_Master
- Ant-Contrib
- ccache
- GIT_Source
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash -x

JENKINS_URL='http://localhost:8080'
NODE_NAME=$1
NODE_IP=$2
NODE_SLAVE_HOME=$3
EXECUTORS=1
SSH_PORT=22
CRED_ID='b8101a03-36e8-4687-a722-d48ad48acd5c'
LABELS=`echo $4 | tr ',' ' '`
USERID='jenkins'

cat <<EOF | java -jar ~/bin/jenkins-cli.jar -s ${JENKINS_URL} -ssh -user admin create-node ${NODE_NAME}
<slave>
<name>${NODE_NAME}</name>
<description></description>
<remoteFS>${NODE_SLAVE_HOME}</remoteFS>
<numExecutors>${EXECUTORS}</numExecutors>
<mode>NORMAL</mode>
<retentionStrategy class="hudson.slaves.RetentionStrategy$Always"/>
<launcher class="hudson.plugins.sshslaves.SSHLauncher" plugin="[email protected]">
<host>${NODE_IP}</host>
<port>${SSH_PORT}</port>
<credentialsId>${CRED_ID}</credentialsId>
</launcher>
<label>${LABELS}</label>
<nodeProperties>
<hudson.slaves.EnvironmentVariablesNodeProperty>
<envVars serialization="custom">
<unserializable-parents/>
<tree-map>
<default>
<comparator class="hudson.util.CaseInsensitiveComparator"/>
</default>
<int>3</int>
<string>JDK7_BOOT_DIR</string>
<string>/usr/lib/jvm/java-1.7.0-openjdk-amd64/</string>
<string>JDK8_BOOT_DIR</string>
<string>/usr/lib/jvm/java-1.8.0-openjdk-amd64/</string>
<string>JDK9_BOOT_DIR</string>
<string>/usr/lib/jvm/java-9-openjdk-amd64/</string>
</tree-map>
</envVars>
</hudson.slaves.EnvironmentVariablesNodeProperty>
</nodeProperties>
<userId>${USERID}</userId>
</slave>
EOF
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
##################
# Jenkins_Master #
##################
- name: Check if machine exists in jenkins
uri:
url: "https://{{ Jenkins_Domain }}/computer/{{ ansible_hostname }}/api/json"
register: jenkins
ignore_errors: true
tags: jenkins_master

- name: SSH into the Jenkins and excute the jenkins-create-node.sh script
become: false
# TODO fetch a var instead of hard coding linux
local_action: command ssh -o StrictHostKeyChecking=no {{ Jenkins_Username }}@{{ Jenkins_Domain }} "/home/{{ Jenkins_Username }}/.jenkins/jenkins-create-node.sh {{ inventory_hostname }} {{ ansible_host }} /home/jenkins linux,{{os}},{{arch}},{{provider}},{{ansible_architecture}},{{type}},{{ansible_distribution|lower}},{{ansible_distribution|lower}}{{ansible_distribution_major_version}}"
when:
- jenkins.status != 200
tags: jenkins_master
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Script must exist on Nagios Master
#
- name: SSH into the Nagios Master and excute the Nagios_Ansible_Config_tool.sh script
local_action: command ssh -o StrictHostKeyChecking=no root@{{ Nagios_Master_IP }} "/usr/local/nagios/Nagios_Ansible_Config_tool/Nagios_Ansible_Config_tool.sh {{ ansible_distribution }} {{ ansible_architecture }} {{ inventory_hostname }} {{ ansible_default_ipv4.address }} "
local_action: command ssh -o StrictHostKeyChecking=no root@{{ Nagios_Master_IP }} "/usr/local/nagios/Nagios_Ansible_Config_tool/Nagios_Ansible_Config_tool.sh {{ ansible_distribution }} {{ ansible_architecture }} {{ inventory_hostname }} {{ ansible_host }} "
when:
- Nagios_Monitoring == "Enabled"
- Nagios_Master_IP is defined
Expand Down

0 comments on commit 5939bfb

Please sign in to comment.