2017-02-07 19:20:06 +01:00
|
|
|
---
|
|
|
|
- block:
|
|
|
|
- name: Jenkins package repository key
|
|
|
|
apt_key: url='{{ jenkins_repo_key }}'
|
|
|
|
|
|
|
|
- name: Install the jenkins stable repository
|
|
|
|
apt_repository: repo='{{ jenkins_stable_repo }}' update_cache=yes
|
|
|
|
when: not jenkins_use_latest
|
|
|
|
|
|
|
|
- name: Install the jenkins latest repository
|
|
|
|
apt_repository: repo='{{ jenkins_latest_repo }}' update_cache=yes
|
|
|
|
when: jenkins_use_latest
|
|
|
|
|
|
|
|
- name: Install jenkins
|
|
|
|
apt: pkg={{ item }} state={{ jenkins_pkg_state }} update_cache=yes cache_valid_time=3600
|
2017-03-16 11:38:07 +01:00
|
|
|
register: jenkins_install
|
2017-02-07 19:20:06 +01:00
|
|
|
with_items: '{{ jenkins_packages }}'
|
|
|
|
|
|
|
|
- name: Install some jenkins requirements
|
|
|
|
apt: pkg={{ item }} state={{ jenkins_pkg_state }} update_cache=yes cache_valid_time=3600
|
|
|
|
with_items: '{{ jenkins_package_requirements }}'
|
|
|
|
|
2017-03-16 11:38:07 +01:00
|
|
|
- name: install sbt launcher
|
|
|
|
copy: src={{ item }} dest=/usr/local/lib/{{ item }}
|
|
|
|
with_items: '{{ jenkins_sbt_launch_jars }}'
|
|
|
|
|
|
|
|
- name: Set the startup jenkins options
|
|
|
|
template: src=jenkins.default.j2 dest=/etc/default/jenkins owner=root group=root mode=0444
|
|
|
|
notify: Restart jenkins
|
|
|
|
|
2017-02-07 19:20:06 +01:00
|
|
|
- name: Ensure that jenkins is started and enabled
|
|
|
|
service: name=jenkins state=started enabled=yes
|
|
|
|
|
|
|
|
when: jenkins_install
|
2017-03-31 19:39:09 +02:00
|
|
|
tags: [ 'jenkins', 'jenkins_master' ]
|
2017-02-07 19:20:06 +01:00
|
|
|
|
2017-03-16 11:38:07 +01:00
|
|
|
- block:
|
|
|
|
# Handle plugins
|
|
|
|
# If Jenkins is installed or updated, wait for pulling the Jenkins CLI, assuming 10s should be sufficiant
|
|
|
|
- name: 120 seconds delay while starting Jenkins
|
|
|
|
wait_for: port={{ jenkins_http_port }} delay={{ jenkins_restart_delay }}
|
|
|
|
|
|
|
|
# Create Jenkins CLI destination directory
|
|
|
|
- name: "Create Jenkins CLI destination directory"
|
|
|
|
file: path={{ jenkins_dest }} state=directory
|
|
|
|
|
|
|
|
- name: Get Jenkins CLI
|
|
|
|
get_url: url=http://localhost:{{ jenkins_http_port }}/jnlpJars/jenkins-cli.jar dest={{ jenkins_cli_dest }} mode=0440
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2017-03-21 18:17:47 +01:00
|
|
|
- name: Install plugins without a specific version
|
|
|
|
jenkins_plugin: name="{{ item.key }}" params='{{ jenkins_access_params }}'
|
|
|
|
register: my_jenkins_plugin_unversioned
|
2017-03-31 19:39:09 +02:00
|
|
|
when: '"version" not in item.value'
|
|
|
|
with_dict: '{{ jenkins_plugins }}'
|
2017-03-21 18:17:47 +01:00
|
|
|
|
|
|
|
- name: Install plugins with a specific version
|
|
|
|
jenkins_plugin: name="{{ item.key }}" version="{{ item.value['version'] }}" params='{{ jenkins_access_params }}'
|
|
|
|
register: my_jenkins_plugin_versioned
|
2017-03-31 19:39:09 +02:00
|
|
|
when: '"version" in item.value'
|
|
|
|
with_dict: '{{ jenkins_plugins }}'
|
2017-03-21 18:17:47 +01:00
|
|
|
|
|
|
|
- name: Initiate the jenkins_restart_required fact
|
|
|
|
set_fact:
|
|
|
|
jenkins_restart_required: no
|
|
|
|
|
|
|
|
- name: Check if restart is required by any of the versioned plugins
|
|
|
|
set_fact:
|
|
|
|
jenkins_restart_required: yes
|
|
|
|
when: item.changed
|
2017-03-31 19:39:09 +02:00
|
|
|
with_items: '{{ my_jenkins_plugin_versioned.results }}'
|
2017-03-21 18:17:47 +01:00
|
|
|
|
|
|
|
- name: Check if restart is required by any of the unversioned plugins
|
|
|
|
set_fact:
|
|
|
|
jenkins_restart_required: yes
|
|
|
|
when: item.changed
|
2017-03-31 19:39:09 +02:00
|
|
|
with_items: '{{ my_jenkins_plugin_unversioned.results }}'
|
2017-03-21 18:17:47 +01:00
|
|
|
|
|
|
|
- name: Restart Jenkins if required
|
2017-03-31 19:39:09 +02:00
|
|
|
become_user: root
|
|
|
|
service: name=jenkins state=restarted
|
2017-03-21 18:17:47 +01:00
|
|
|
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 }}'
|
2017-03-31 19:39:09 +02:00
|
|
|
when: '"pinned" in item.value'
|
|
|
|
with_dict: '{{ jenkins_plugins }}'
|
2017-03-21 18:17:47 +01:00
|
|
|
|
|
|
|
- name: Plugin enabling
|
|
|
|
jenkins_plugin: name="{{ item.key }}" state="{{ 'enabled' if item.value['enabled'] else 'disabled'}}" params='{{ jenkins_access_params }}'
|
2017-03-31 19:39:09 +02:00
|
|
|
when: '"enabled" in item.value'
|
|
|
|
with_dict: '{{ jenkins_plugins }}'
|
2017-03-16 11:38:07 +01:00
|
|
|
|
|
|
|
become: True
|
|
|
|
become_user: '{{ jenkins_username }}'
|
|
|
|
when: jenkins_install
|
2017-03-31 19:39:09 +02:00
|
|
|
tags: [ 'jenkins', 'jenkins_plugins', 'jenkins_master' ]
|
2017-03-16 11:38:07 +01:00
|
|
|
|
2017-02-07 19:20:06 +01:00
|
|
|
- block:
|
|
|
|
- name: Ensure that jenkins is stoppend and disabled
|
|
|
|
service: name=jenkins state=stopped enabled=no
|
|
|
|
|
|
|
|
- name: Remove the jenkins requirements
|
|
|
|
apt: pkg={{ item }} state=absent
|
|
|
|
with_items: '{{ jenkins_package_requirements }}'
|
|
|
|
|
|
|
|
- name: Remove jenkins
|
|
|
|
apt: pkg={{ item }} state=absent
|
|
|
|
with_items: '{{ jenkins_packages }}'
|
|
|
|
|
|
|
|
- name: Remove the jenkins stable repository
|
|
|
|
apt_repository: repo='{{ jenkins_stable_repo }}' state=absent update_cache=yes
|
|
|
|
|
|
|
|
- name: Remove the jenkins latest repository
|
|
|
|
apt_repository: repo='{{ jenkins_latest_repo }}' state=absent update_cache=yes
|
|
|
|
|
|
|
|
- name: Remove the jenkins package repository key
|
|
|
|
apt_key: url='{{ jenkins_repo_key }}' state=absent
|
|
|
|
|
|
|
|
when: not jenkins_install
|
2017-03-31 19:39:09 +02:00
|
|
|
tags: [ 'jenkins', 'jenkins_master' ]
|