diff options
Diffstat (limited to 'tasks')
-rw-r--r-- | tasks/keys.yml | 33 | ||||
-rw-r--r-- | tasks/main.yml | 5 |
2 files changed, 38 insertions, 0 deletions
diff --git a/tasks/keys.yml b/tasks/keys.yml new file mode 100644 index 0000000..98c6136 --- /dev/null +++ b/tasks/keys.yml | |||
@@ -0,0 +1,33 @@ | |||
1 | --- | ||
2 | - name: Build scoped path | ||
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) }}" | ||
5 | vars: | ||
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) }}" | ||
8 | |||
9 | - name: Check key existence | ||
10 | uri: | ||
11 | url: "{{ rundeck_api_url }}/{{ rundeck_api_version }}/storage/keys/{{ rundeck_key_full_path }}" | ||
12 | method: GET | ||
13 | headers: | ||
14 | Accept: application/json | ||
15 | X-Rundeck-Auth-Token: "{{ rundeck_api_token }}" | ||
16 | status_code: [200, 404] | ||
17 | register: rundeck_existing_key | ||
18 | |||
19 | - name: Set method | ||
20 | set_fact: | ||
21 | rundeck_key_uri_method: "{{ (rundeck_existing_key.status == 404) | ternary('POST', 'PUT') }}" | ||
22 | |||
23 | - name: Import key | ||
24 | uri: | ||
25 | url: "{{ rundeck_api_url }}/{{ rundeck_api_version }}/storage/keys/{{ rundeck_key_full_path }}" | ||
26 | method: "{{ rundeck_key_uri_method }}" | ||
27 | headers: | ||
28 | Accept: application/json | ||
29 | Content-Type: "{{ item.type }}" | ||
30 | X-Rundeck-Auth-Token: "{{ rundeck_api_token }}" | ||
31 | status_code: [200, 201] | ||
32 | body: "{{ item.value }}" | ||
33 | body_format: raw | ||
diff --git a/tasks/main.yml b/tasks/main.yml index 3d41031..644fef0 100644 --- a/tasks/main.yml +++ b/tasks/main.yml | |||
@@ -3,3 +3,8 @@ | |||
3 | include_tasks: rundeck.yml | 3 | include_tasks: rundeck.yml |
4 | tags: | 4 | tags: |
5 | - rundeck-jobs | 5 | - rundeck-jobs |
6 | - name: Include rundeck keys | ||
7 | include_tasks: keys.yml | ||
8 | tags: | ||
9 | - rundeck-keys | ||
10 | with_items: "{{ rundeck_jobs_keys }}" | ||