Skip to content

Commit

Permalink
Merge pull request #14 from wcm-io-devops/feature/update_jenkins_2.346.2
Browse files Browse the repository at this point in the history
Raise plugin- and/or role versions
  • Loading branch information
tobias-richter committed Aug 10, 2022
2 parents 295fed6 + a7d6dc5 commit 0e7d9ba
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 30 deletions.
11 changes: 6 additions & 5 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ jenkins_casc_config_path_configure: false
# Config files/templates to upload
jenkins_casc_config_fileglobs: []

# Controls if files that existing files in the 'jenkins_casc_config_path' are deleted when they are not included in the 'jenkins_casc_config_fileglobs'
# Deletion will only be executed when at least one file was uploaded to the 'jenkins_casc_config_path'
# Controls if files that existing files in the 'jenkins_casc_config_path' are deleted
# when they are not included in the 'jenkins_casc_config_fileglobs'. Deletion will only
# be executed when at least one file was uploaded to the 'jenkins_casc_config_path'
jenkins_casc_config_unmanaged_delete: false

# The timeout for jenkins_script tasks in seconds
Expand All @@ -48,13 +49,13 @@ jenkins_casc_no_log: true
# Plugins needed for configuration-as-code
jenkins_casc_plugins_present:
- name: configuration-as-code
version: "1414.v878271fc496f"
version: "1512.vb_79d418d5fc8"
- name: configuration-as-code-groovy
version: "1.1"
- name: snakeyaml-api
version: "1.29.1"
version: "1.30.2-76.vc104f7ce9870"
- name: job-dsl
version: "1.78.3"
version: "1.81"

# Plugins no longer needed for configuration-as-code
jenkins_casc_plugins_absent:
Expand Down
2 changes: 1 addition & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ galaxy_info:
company: pro!vision
issue_tracker_url: https://wcm-io.atlassian.net
license: Apache
min_ansible_version: 2.7
min_ansible_version: "2.7"

platforms:
- name: EL
Expand Down
8 changes: 4 additions & 4 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
- name: "configure : check if '{{ jenkins_casc_config_path }}' exists."
stat:
ansible.builtin.stat:
path: "{{ jenkins_casc_config_path }}"
register: jenkins_casc_config_path_result

- name: "Fail when '{{ jenkins_casc_config_path }}' does not exist."
fail:
ansible.builtin.fail:
msg: >-
No file or directory found with path '{{ jenkins_casc_config_path }}'.
Ensure that the configuration is on the instance before calling this role."
Expand All @@ -26,12 +26,12 @@
| regex_replace('\\s*Result:\\s*(.*)\\n*$', '\\1') | from_json).changed

- name: "configure : set _jenkins_casc_plugin_configure_result fact."
set_fact:
ansible.builtin.set_fact:
_jenkins_casc_plugin_configure_result:
"{{ (_jenkins_casc_plugin_configure_result.output | regex_replace('\\s*Result:\\s*(.*)\\n*$', '\\1') | from_json) }}"

- name: "configure : fail when configuration throws exception."
fail:
ansible.builtin.fail:
msg:
- Exception thrown during applying of configuration, check your configuration!
- "{{ _jenkins_casc_plugin_configure_result.msg }}"
Expand Down
8 changes: 4 additions & 4 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
---
- include_tasks: secrets.yml
- ansible.builtin.include_tasks: secrets.yml
tags:
- jcasc-secrets
when: jenkins_casc_secrets | length > 0

- include_tasks: upload.yml
- ansible.builtin.include_tasks: upload.yml
tags:
- jcasc-upload

- include_tasks: configure.yml
- ansible.builtin.include_tasks: configure.yml
tags:
- jcasc-configure
when: jenkins_casc_config_path_configure

- name: "trigger reload handler when necessary."
command: /bin/true
ansible.builtin.command: /bin/true
changed_when: true
when:
# only trigger when configure result is false, since this will do a implicit reload
Expand Down
4 changes: 2 additions & 2 deletions tasks/reload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
- jcasc-reload

- name: "reload : set _jenkins_casc_upload_files_result fact."
set_fact:
ansible.builtin.set_fact:
_jenkins_casc_upload_files_result:
"{{ (_jenkins_casc_upload_files_result.output | regex_replace('\\s*Result:\\s*(.*)\\n*$', '\\1') | from_json) }}"

- name: "reload : fail when configuration throws exception."
fail:
ansible.builtin.fail:
msg:
- Exception thrown during applying of configuration, check your configuration!
- "{{ _jenkins_casc_upload_files_result.msg }}"
Expand Down
16 changes: 8 additions & 8 deletions tasks/secrets.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
---
- name: "secrets : get user home dir."
become: yes
getent:
ansible.builtin.getent:
database: passwd
key: "{{ jenkins_casc_owner }}"
split: ":"

- name: "secrets : set user home dir."
set_fact:
ansible.builtin.set_fact:
_secrets_home_dir: "{{ getent_passwd[jenkins_casc_owner][4] }}"
failed_when: _secrets_home_dir | length == 0

- name: "secrets : create secrets dir."
file:
ansible.builtin.file:
path: "{{ jenkins_casc_secrets_dir }}"
state: directory
owner: "{{ jenkins_casc_owner }}"
group: "{{ jenkins_casc_group }}"
mode: 0700

- name: "secrets : deploy secret."
copy:
ansible.builtin.copy:
dest: "{{ jenkins_casc_secrets_dir }}/{{ secret.id }}"
content: "{{ secret.value }}"
owner: "{{ jenkins_casc_owner }}"
Expand All @@ -34,12 +34,12 @@
- name: "secrets : unmanaged."
block:
- name: "secrets : unmanaged : find files in {{ jenkins_casc_secrets_dir }}."
find:
ansible.builtin.find:
paths: "{{ jenkins_casc_secrets_dir }}"
register: _jenkins_casc_secrets_existing_files

- name: "secrets : unmanaged : delete unmanaged secrets."
file:
ansible.builtin.file:
path: "{{ jenkins_casc_secrets_dir }}/{{ item }}"
state: absent
with_items: "{{ _jenkins_casc_secrets_existing_files.files | map(attribute='path') | map('basename') | list
Expand All @@ -48,7 +48,7 @@
when: jenkins_casc_secrets_unmanaged_delete

- name: "secrets : configure secrets env var."
blockinfile:
ansible.builtin.blockinfile:
dest: "{{ _secrets_home_dir }}/.profile"
create: yes
owner: "{{ jenkins_casc_owner }}"
Expand All @@ -60,7 +60,7 @@
register: _profile_result

- name: Restart Jenkins when required. # noqa 503
include_role:
ansible.builtin.include_role:
name: wcm_io_devops.jenkins_service
vars:
jenkins_service_state: "restarted"
Expand Down
12 changes: 6 additions & 6 deletions tasks/upload.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
- name: "upload : calculate files to upload order to check that no files exist with overlapping names."
set_fact:
ansible.builtin.set_fact:
_jenkins_casc_found_config_files: "{{ _jenkins_casc_found_config_files | default([]) + [item] }}"
with_fileglob: "{{ jenkins_casc_config_fileglobs }}"

- name: "upload : fail on overlapping file names."
fail:
ansible.builtin.fail:
msg:
- "Found duplicate file(s) to deploy!"
- "Please ensure that the filenames are unique, otherwise unexpected result may occur!"
Expand All @@ -15,15 +15,15 @@
_jenkins_casc_found_config_files | default({}) | map('basename') | list | unique

- name: "upload : create configuration dir."
file:
ansible.builtin.file:
path: "{{ jenkins_casc_config_path }}"
state: directory
owner: "{{ jenkins_casc_owner }}"
group: "{{ jenkins_casc_group }}"
mode: 0770

- name: "upload : upload files/templates."
template:
ansible.builtin.template:
src: "{{ item }}"
owner: "{{ jenkins_casc_owner }}"
group: "{{ jenkins_casc_group }}"
Expand All @@ -35,12 +35,12 @@
- name: "upload : unmanaged."
block:
- name: "upload : unmanaged : find files in {{ jenkins_casc_config_path }}."
find:
ansible.builtin.find:
paths: "{{ jenkins_casc_config_path }}"
register: _jenkins_casc_config_existing_files

- name: "upload : unmanaged : delete unmanaged files."
file:
ansible.builtin.file:
path: "{{ item }}"
state: absent
# build list of uploaded and found file paths and delete the difference
Expand Down

0 comments on commit 0e7d9ba

Please sign in to comment.