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
|
|
|
|
tags: jenkins
|
|
|
|
|
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 }}
|
|
|
|
when: jenkins_install | changed
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
# 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
|
|
|
|
- name: Create the Jenkins administrative user password file
|
|
|
|
copy: content={{ jenkins_admin_pwd }} dest={{ jenkins_admin_user_pwd_file }} mode=600
|
|
|
|
|
|
|
|
# login as the Jenkins administrative user
|
|
|
|
- name: login as the Jenkins administrative user
|
|
|
|
command: java -jar {{ jenkins_cli_dest }} -s http://localhost:{{ jenkins_http_port }} login --username {{ jenkins_admin_user }} --password-file {{ jenkins_admin_user_pwd_file }}
|
|
|
|
when: (jenkins_plugins is defined) and (jenkins_updates | changed)
|
|
|
|
|
|
|
|
# Install/update Jenkins plugins
|
|
|
|
- name: Install/update plugins
|
|
|
|
command: java -jar {{ jenkins_cli_dest }} -s http://localhost:{{ jenkins_http_port }} install-plugin {{ item }}
|
|
|
|
when: (jenkins_plugins is defined) and (jenkins_updates | changed)
|
|
|
|
with_items: '{{ jenkins_plugins }}'
|
|
|
|
|
|
|
|
# Wait for Jenkins to install plugins, assuming 10s should be sufficiant
|
|
|
|
- name: 120 seconds delay while installing plugins
|
|
|
|
wait_for: port={{ jenkins_http_port }} delay={{ jenkins_restart_delay }}
|
|
|
|
when: jenkins_updates | changed
|
|
|
|
|
|
|
|
# Safe-restart Jenkins
|
|
|
|
- name: Safe-restart Jenkins
|
|
|
|
command: java -jar {{ jenkins_cli_dest }} -s http://localhost:{{ jenkins_http_port }} safe-restart
|
|
|
|
when: jenkins_updates | changed
|
|
|
|
|
|
|
|
- name: logout the Jenkins administrative user
|
|
|
|
command: java -jar {{ jenkins_cli_dest }} -s http://localhost:{{ jenkins_http_port }} logout
|
|
|
|
when: (jenkins_plugins is defined) and (jenkins_updates | changed)
|
|
|
|
ignore_errors: True
|
|
|
|
|
|
|
|
become: True
|
|
|
|
become_user: '{{ jenkins_username }}'
|
|
|
|
when: jenkins_install
|
|
|
|
tags: [ 'jenkins', 'jenkins_plugins' ]
|
|
|
|
|
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
|
|
|
|
tags: jenkins
|