aboutsummaryrefslogtreecommitdiffhomepage
path: root/tasks/keys.yml
diff options
context:
space:
mode:
Diffstat (limited to 'tasks/keys.yml')
-rw-r--r--tasks/keys.yml43
1 files changed, 22 insertions, 21 deletions
diff --git a/tasks/keys.yml b/tasks/keys.yml
index 98c6136..7ca0904 100644
--- a/tasks/keys.yml
+++ b/tasks/keys.yml
@@ -1,33 +1,34 @@
1--- 1---
2- name: Build scoped path 2- name: Set scope variables
3 set_fact: 3 set_fact:
4 rundeck_key_full_path: "{{ rundeck_keys_scoped_by_project | default(true) | ternary('project/' + rundeck_project + '/' + key_group_path, key_group_path) }}" 4 rundeck_keys_base_path: "{{ rundeck_keys_scoped_by_project | default(true) | ternary('project/' + rundeck_project + '/' + rundeck_keys_group_path, rundeck_keys_group_path) }}"
5 vars: 5 vars:
6 group_name: "{{ rundeck_jobs_group | default('') }}" 6 group_name: "{{ rundeck_jobs_group | default('') }}"
7 key_group_path: "{{ rundeck_keys_scoped_by_group | default((group_name|length) > 0) | ternary(group_name + '/' + item.path, item.path) }}" 7 rundeck_keys_group_path: "{{ rundeck_keys_scoped_by_group | default((group_name|length) > 0) | ternary(group_name, '') }}"
8 8
9- name: Check key existence 9- name: Include rundeck key
10 uri: 10 include_tasks: key.yml
11 url: "{{ rundeck_api_url }}/{{ rundeck_api_version }}/storage/keys/{{ rundeck_key_full_path }}" 11 with_items: "{{ rundeck_jobs_keys }}"
12 method: GET 12
13 headers: 13- name: Get all stored keys
14 Accept: application/json 14 script:
15 X-Rundeck-Auth-Token: "{{ rundeck_api_token }}" 15 cmd: "{{ role_path }}/files/fetch_keys.sh {{ rundeck_api_url }}/{{ rundeck_api_version }} {{ rundeck_api_token }} keys/{{ rundeck_keys_base_path }}"
16 status_code: [200, 404] 16 register: rundeck_existing_keys
17 register: rundeck_existing_key 17 when: rundeck_remove_missing_keys
18 18
19- name: Set method 19- name: "Prepare list of keys to remove"
20 set_fact: 20 set_fact:
21 rundeck_key_uri_method: "{{ (rundeck_existing_key.status == 404) | ternary('POST', 'PUT') }}" 21 rundeck_existing_keys: "{{ rundeck_existing_keys.stdout_lines | list }}"
22 rundeck_known_keys: "{{ rundeck_jobs_keys | map(attribute='path') | list }}"
23 when: rundeck_remove_missing_keys
22 24
23- name: Import key 25- name: "Remove jobs not declared"
24 uri: 26 uri:
25 url: "{{ rundeck_api_url }}/{{ rundeck_api_version }}/storage/keys/{{ rundeck_key_full_path }}" 27 url: "{{ rundeck_api_url }}/{{ rundeck_api_version }}/storage/keys/{{ rundeck_keys_base_path }}/{{ item }}"
26 method: "{{ rundeck_key_uri_method }}" 28 method: DELETE
27 headers: 29 headers:
28 Accept: application/json 30 Accept: application/json
29 Content-Type: "{{ item.type }}"
30 X-Rundeck-Auth-Token: "{{ rundeck_api_token }}" 31 X-Rundeck-Auth-Token: "{{ rundeck_api_token }}"
31 status_code: [200, 201] 32 status_code: [204, 404]
32 body: "{{ item.value }}" 33 with_items: "{{ rundeck_existing_keys | difference(rundeck_known_keys) }}"
33 body_format: raw 34 when: rundeck_remove_missing_keys