From c5b314e1ee908bf87badbe9e750d2ac7d83d3d0e Mon Sep 17 00:00:00 2001 From: David Galloway Date: Fri, 4 Aug 2017 11:28:47 -0400 Subject: [PATCH] ansible: Update Jenkins plugins tasks - Have to enable CLI to use jenkins-cli - Now compatible with ansible > v2 Signed-off-by: David Galloway --- .../roles/ansible-jenkins/handlers/main.yml | 5 ++ .../roles/ansible-jenkins/tasks/jenkins.yml | 2 + .../roles/ansible-jenkins/tasks/plugins.yml | 59 +++++++++++++++++-- 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/ansible/roles/ansible-jenkins/handlers/main.yml b/ansible/roles/ansible-jenkins/handlers/main.yml index 759b833a..1b67b768 100644 --- a/ansible/roles/ansible-jenkins/handlers/main.yml +++ b/ansible/roles/ansible-jenkins/handlers/main.yml @@ -6,3 +6,8 @@ service: name: nginx state: restarted + +- name: stop nginx + service: + name: nginx + state: stopped diff --git a/ansible/roles/ansible-jenkins/tasks/jenkins.yml b/ansible/roles/ansible-jenkins/tasks/jenkins.yml index 4adb0601..d018c12e 100644 --- a/ansible/roles/ansible-jenkins/tasks/jenkins.yml +++ b/ansible/roles/ansible-jenkins/tasks/jenkins.yml @@ -22,5 +22,7 @@ - include: config.yml - include: plugins.yml + tags: + - plugins - include: config.yml diff --git a/ansible/roles/ansible-jenkins/tasks/plugins.yml b/ansible/roles/ansible-jenkins/tasks/plugins.yml index 0077aa01..9308fe77 100644 --- a/ansible/roles/ansible-jenkins/tasks/plugins.yml +++ b/ansible/roles/ansible-jenkins/tasks/plugins.yml @@ -1,15 +1,46 @@ --- +- name: Make sure Jenkins CLI is enabled + blockinfile: + path: "{{ jenkins_lib }}/jenkins.CLI.xml" + create: yes + block: | + + + true + + +- name: Temporarily disable public http access + service: + name: nginx + state: stopped + +- name: Temporarily disable security so anonymous can use jenkins-cli + replace: + path: "{{ jenkins_lib }}/config.xml" + regexp: 'true' + replace: 'false' + backup: yes + register: original_jenkins_config + +- name: Restart Jenkins with no security so we can use jenkins-cli + service: + name: jenkins + state: restarted + - name: List plugins shell: java -jar {{ jenkins.cli_dest }} -s http://localhost:{{ jenkins_port }} list-plugins | cut -f 1 -d ' ' when: plugins is defined register: plugins_installed + # Jenkins takes a while to come back up + retries: 10 + until: '"503" not in plugins_installed.stderr and plugins_installed.stdout != ""' - name: Install/update plugins shell: java -jar {{ jenkins.cli_dest }} -s http://localhost:{{ jenkins_port }} install-plugin {{ item }} when: plugins_installed.changed and plugins_installed.stdout.find('{{ item }}') == -1 - with_items: plugins - notify: - - 'restart jenkins' + with_items: "{{ plugins }}" + # This is only here because the postbuildscript plugin is currently deprecated + ignore_errors: yes - name: List plugins to be updated shell: java -jar {{ jenkins.cli_dest }} -s http://localhost:{{ jenkins_port }} list-plugins | grep ')$' | cut -f 1 -d ' ' | sed ':a;N;$!ba;s/\n/ /g' @@ -17,8 +48,24 @@ - name: Update plugins shell: java -jar {{ jenkins.cli_dest }} -s http://localhost:{{ jenkins_port }} install-plugin {{ item }} - with_items: plugins_updates.stdout.split() + with_items: "{{ plugins_updates.stdout.split() }}" when: plugins_updates.stdout != '' ignore_errors: yes - notify: - - 'restart jenkins' + +- name: Restore original Jenkins config to re-enable auth + copy: + src: "{{ original_jenkins_config.backup_file }}" + dest: "{{ jenkins_lib }}/config.xml" + remote_src: yes + owner: jenkins + group: jenkins + +- name: Restart Jenkins with security + service: + name: jenkins + state: restarted + +- name: Re-enable public http access + service: + name: nginx + state: started -- 2.39.5