Skip to content

Commit

Permalink
Add initial support for adding Jenkins slaves
Browse files Browse the repository at this point in the history
  • Loading branch information
leifmadsen committed Aug 15, 2016
1 parent c7ab30e commit d4c9205
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions jenkins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
sudo_defaults:
- defaults: '!requiretty'

tasks:
- name: Set facts for later use
set_fact:
jenkins_jar_location: "{{ jenkins_jar_location }}"
jenkins_hostname: "{{ jenkins_hostname }}"
jenkins_http_port: "{{ jenkins_http_port }}"
jenkins_url_prefix: "{{ jenkins_url_prefix }}"
jenkins_admin_username: "{{ jenkins_admin_username }}"
jenkins_admin_password: "{{ jenkins_admin_password }}"

post_tasks:
- name: Add jenkins user to wheel group
user:
Expand Down Expand Up @@ -253,3 +263,45 @@
authorized_key:
user: root
key: "{{ jenkins_slave_pub.stdout }}"

- hosts: jenkins_master
become: yes
tags:
- jenkins_slave_test

vars_files:
- ~/.ansible/vars/cira_vars.yml

tasks:
# TODO: This is kind of hacky since it doesn't deal with multiple jenkins
# slaves. We'll need to circle back and make this deal with lists.
- name: Check if our node already exists
ignore_errors: true
command: >
java -jar {{ jenkins_jar_location }} -s http://{{ jenkins_hostname }}:{{ jenkins_http_port }}{{ jenkins_url_prefix | default('') }}/
get-node {{ slave_name }}
--username {{ jenkins_admin_username }}
--password {{ jenkins_admin_password }}
register: jenkins_cli_get_node

- debug: var=jenkins_cli_get_node

- name: Deploy template for Jenkins slave node
template:
src: jenkins_slave.j2
dest: /tmp/jenkins_slave_{{ slave_name }}.tmpl
when: jenkins_cli_get_node.stderr is defined and jenkins_cli_get_node.stderr != ""

- name: Add Jenkins slave node to the master
shell: >
java -jar {{ jenkins_jar_location }} -s http://{{ jenkins_hostname }}:{{ jenkins_http_port }}{{ jenkins_url_prefix | default('') }}/
create-node {{ slave_name }}
--username {{ jenkins_admin_username }}
--password {{ jenkins_admin_password }} < /tmp/jenkins_slave_{{ slave_name }}.tmpl
when: jenkins_cli_get_node.stderr is defined and jenkins_cli_get_node.stderr != ""

- name: Remove template for Jenkins slave node
file:
name: /tmp/jenkins_slave_{{ slave_name }}.tmpl
state: absent
when: slave_name is defined and jenkins_cli_get_node.stderr != ""

0 comments on commit d4c9205

Please sign in to comment.