87 lines
2.5 KiB
YAML
87 lines
2.5 KiB
YAML
|
---
|
||
|
- name: Check if jenkins_init_file exists.
|
||
|
stat:
|
||
|
path: "{{ jenkins_init_file }}"
|
||
|
register: jenkins_init_file_stat
|
||
|
|
||
|
- name: Ensure jenkins_init_file exists.
|
||
|
file:
|
||
|
path: "{{ jenkins_init_file }}"
|
||
|
state: touch
|
||
|
mode: 0644
|
||
|
when: not jenkins_init_file_stat.stat.exists
|
||
|
|
||
|
- name: Modify variables in init file.
|
||
|
lineinfile:
|
||
|
dest: "{{ jenkins_init_file }}"
|
||
|
insertafter: '^{{ item.option }}='
|
||
|
regexp: '^{{ item.option }}=\"\${{ item.option }} '
|
||
|
line: '{{ item.option }}="${{ item.option }} {{ item.value }}"'
|
||
|
state: present
|
||
|
mode: 0644
|
||
|
with_items: "{{ jenkins_init_changes }}"
|
||
|
register: jenkins_init_prefix
|
||
|
|
||
|
- name: Ensure jenkins_home {{ jenkins_home }} exists.
|
||
|
file:
|
||
|
path: "{{ jenkins_home }}"
|
||
|
state: directory
|
||
|
owner: jenkins
|
||
|
group: jenkins
|
||
|
mode: u+rwx
|
||
|
follow: true
|
||
|
|
||
|
- name: Set the Jenkins home directory.
|
||
|
lineinfile:
|
||
|
dest: "{{ jenkins_init_file }}"
|
||
|
regexp: '^JENKINS_HOME=.*'
|
||
|
line: 'JENKINS_HOME={{ jenkins_home }}'
|
||
|
mode: 0644
|
||
|
register: jenkins_home_config
|
||
|
|
||
|
- name: Immediately restart Jenkins on init config changes.
|
||
|
service: name=jenkins state=restarted
|
||
|
when: jenkins_init_prefix.changed
|
||
|
tags: ['skip_ansible_lint']
|
||
|
|
||
|
- name: Set HTTP port in Jenkins config.
|
||
|
lineinfile:
|
||
|
backrefs: true
|
||
|
dest: "{{ jenkins_init_file }}"
|
||
|
regexp: '^{{ jenkins_http_port_param }}='
|
||
|
line: '{{ jenkins_http_port_param }}={{ jenkins_http_port }}'
|
||
|
mode: 0644
|
||
|
register: jenkins_http_config
|
||
|
|
||
|
- name: Create custom init scripts directory.
|
||
|
file:
|
||
|
path: "{{ jenkins_home }}/init.groovy.d"
|
||
|
state: directory
|
||
|
owner: "{{ jenkins_process_user }}"
|
||
|
group: "{{ jenkins_process_group }}"
|
||
|
mode: 0775
|
||
|
|
||
|
- name: Configure proxy config for Jenkins
|
||
|
template:
|
||
|
src: proxy.xml
|
||
|
dest: "{{ jenkins_home }}/proxy.xml"
|
||
|
owner: "{{ jenkins_process_user }}"
|
||
|
group: "{{ jenkins_process_group }}"
|
||
|
mode: 0664
|
||
|
register: jenkins_proxy_config
|
||
|
when:
|
||
|
- jenkins_proxy_host | length > 0
|
||
|
- jenkins_proxy_port | length > 0
|
||
|
|
||
|
- name: Trigger handlers immediately in case Jenkins was installed
|
||
|
meta: flush_handlers
|
||
|
|
||
|
- name: Immediately restart Jenkins on http or user changes.
|
||
|
service: name=jenkins state=restarted
|
||
|
when: >
|
||
|
(jenkins_users_config is defined and jenkins_users_config.changed)
|
||
|
or (jenkins_http_config is defined and jenkins_http_config.changed)
|
||
|
or (jenkins_home_config is defined and jenkins_home_config.changed)
|
||
|
or (jenkins_proxy_config is defined and jenkins_proxy_config.changed)
|
||
|
tags: ['skip_ansible_lint']
|