library/roles/jenkins/master: Use the jenkins_plugin module to install the plugins.

This commit is contained in:
Andrea Dell'Amico 2017-03-21 18:17:47 +01:00
parent 020fea5444
commit 834062b38b
2 changed files with 94 additions and 64 deletions

View File

@ -19,6 +19,7 @@ jenkins_sbt_launch_jars:
jenkins_http_port: 8080 jenkins_http_port: 8080
jenkins_http_host: 127.0.0.1 jenkins_http_host: 127.0.0.1
jenkins_local_url: 'http://{{ jenkins_http_host }}:{{ jenkins_http_port }}'
jenkins_dest: "/var/lib/jenkins" jenkins_dest: "/var/lib/jenkins"
jenkins_webroot: /var/cache/jenkins/war jenkins_webroot: /var/cache/jenkins/war
jenkins_username: jenkins jenkins_username: jenkins
@ -35,37 +36,41 @@ jenkins_cli_dest: "{{ jenkins_dest }}/jenkins-cli.jar" # Jenkins CLI destination
jenkins_updates_dest: "{{ jenkins_dest }}/updates_jenkins.json" # Jenkins updates file jenkins_updates_dest: "{{ jenkins_dest }}/updates_jenkins.json" # Jenkins updates file
jenkins_admin_user_pwd_file: "{{ jenkins_dest }}/.jenkins_admin_pwd" jenkins_admin_user_pwd_file: "{{ jenkins_dest }}/.jenkins_admin_pwd"
jenkins_access_params:
url_username: '{{ jenkins_admin_user }}'
url_password: '{{ jenkins_admin_pwd }}'
url: '{{ jenkins_local_url }}'
jenkins_plugins: jenkins_plugins:
- 'chucknorris' chucknorris:
# - 'configurationslicing' enabled: True
- 'credentials' credentials:
- 'disk-usage' enabled: True
- 'email-ext' disk-usage:
- 'embeddable-build-status' enabled: True
- 'external-monitor-job' github:
- 'ldap' enabled: True
- 'git' github-api:
- 'github' enabled: True
- 'github-api' global-build-stats:
# - 'global-build-stats' enabled: True
- 'javadoc' mailer:
- 'job-dsl' enabled: True
# - 'jobConfigHistory' maven-plugin:
- 'mailer' enabled: True
- 'maven-plugin' monitoring:
- 'monitoring' enabled: True
- 'extended-read-permission' extended-read-permission:
- 'dependency-queue-plugin' enabled: True
- 'dependencyanalyzer' dependency-queue-plugin:
- 'depgraph-view' enabled: True
- 'progress-bar-column-plugin' dependencyanalyzer:
- 'publish-over-ftp-plugin' enabled: True
- 'redmine-plugin' depgraph-view:
- 'slave-utilization-plugin' enabled: True
- 'sonar' progress-bar-column-plugin:
- 'ssh-credentials' enabled: True
- 'ssh-slaves' slave-utilization-plugin:
- 'subversion' enabled: True
# - 'timestamper' build-pipeline-plugin:
- 'translation' enabled: True
- 'naginator'

View File

@ -48,45 +48,70 @@
- name: Get Jenkins CLI - name: Get Jenkins CLI
get_url: url=http://localhost:{{ jenkins_http_port }}/jnlpJars/jenkins-cli.jar dest={{ jenkins_cli_dest }} mode=0440 get_url: url=http://localhost:{{ jenkins_http_port }}/jnlpJars/jenkins-cli.jar dest={{ jenkins_cli_dest }} mode=0440
# Get latest Jenkins update file
- name: Get Jenkins updates
get_url: url=http://updates.jenkins-ci.org/update-center.json dest={{ jenkins_updates_dest }} thirsty=yes mode=0660
register: jenkins_updates
# Jenkins Update-center
- name: Update-center Jenkins
shell: "cat {{ jenkins_updates_dest }} | sed '1d;$d' | curl -X POST -H 'Accept: application/json' -d @- http://localhost:{{ jenkins_http_port }}/updateCenter/byId/default/postBack"
when: jenkins_updates | changed
# Create the Jenkins administrative user password file # Create the Jenkins administrative user password file
- name: Create the Jenkins administrative user password file - name: Create the Jenkins administrative user password file
copy: content={{ jenkins_admin_pwd }} dest={{ jenkins_admin_user_pwd_file }} mode=600 copy: content={{ jenkins_admin_pwd }} dest={{ jenkins_admin_user_pwd_file }} mode=600
# login as the Jenkins administrative user - name: Install plugins without a specific version
- name: login as the Jenkins administrative user jenkins_plugin: name="{{ item.key }}" params='{{ jenkins_access_params }}'
command: java -jar {{ jenkins_cli_dest }} -s http://localhost:{{ jenkins_http_port }} login --username {{ jenkins_admin_user }} --password-file {{ jenkins_admin_user_pwd_file }} register: my_jenkins_plugin_unversioned
when: (jenkins_plugins is defined) and (jenkins_updates | changed) when: 'version' not in item.value
with_dict: jenkins_plugins
# Install/update Jenkins plugins - name: Install plugins with a specific version
- name: Install/update plugins jenkins_plugin: name="{{ item.key }}" version="{{ item.value['version'] }}" params='{{ jenkins_access_params }}'
command: java -jar {{ jenkins_cli_dest }} -s http://localhost:{{ jenkins_http_port }} install-plugin {{ item }} register: my_jenkins_plugin_versioned
when: (jenkins_plugins is defined) and (jenkins_updates | changed) when: 'version' in item.value
with_items: '{{ jenkins_plugins }}' with_dict: jenkins_plugins
# Wait for Jenkins to install plugins, assuming 10s should be sufficiant - name: Initiate the jenkins_restart_required fact
- name: 120 seconds delay while installing plugins set_fact:
wait_for: port={{ jenkins_http_port }} delay={{ jenkins_restart_delay }} jenkins_restart_required: no
when: jenkins_updates | changed
# Safe-restart Jenkins - name: Check if restart is required by any of the versioned plugins
- name: Safe-restart Jenkins set_fact:
command: java -jar {{ jenkins_cli_dest }} -s http://localhost:{{ jenkins_http_port }} safe-restart jenkins_restart_required: yes
when: jenkins_updates | changed when: item.changed
with_items: my_jenkins_plugin_versioned.results
- name: logout the Jenkins administrative user - name: Check if restart is required by any of the unversioned plugins
command: java -jar {{ jenkins_cli_dest }} -s http://localhost:{{ jenkins_http_port }} logout set_fact:
when: (jenkins_plugins is defined) and (jenkins_updates | changed) jenkins_restart_required: yes
ignore_errors: True when: item.changed
with_items: my_jenkins_plugin_unversioned.results
- name: Restart Jenkins if required
service: name=jenkins state= restarted
when: jenkins_restart_required
- name: Wait for Jenkins to start up
uri:
url: '{{ jenkins_local_url }}'
status_code: 200
timeout: 5
register: jenkins_service_status
# Keep trying for 5 mins in 5 sec intervals
retries: 60
delay: 5
until: >
'status' in jenkins_service_status and
jenkins_service_status['status'] == 200
when: jenkins_restart_required
- name: Reset the jenkins_restart_required fact
set_fact:
jenkins_restart_required: no
when: jenkins_restart_required
- name: Plugin pinning
jenkins_plugin: name="{{ item.key }}" state="{{ 'pinned' if item.value['pinned'] else 'unpinned'}}" params='{{ jenkins_access_params }}'
when: 'pinned' in item.value
with_dict: jenkins_plugins
- name: Plugin enabling
jenkins_plugin: name="{{ item.key }}" state="{{ 'enabled' if item.value['enabled'] else 'disabled'}}" params='{{ jenkins_access_params }}'
when: 'enabled' in item.value
with_dict: jenkins_plugins
become: True become: True
become_user: '{{ jenkins_username }}' become_user: '{{ jenkins_username }}'