diff options
Diffstat (limited to 'tasks/keys.yml')
-rw-r--r-- | tasks/keys.yml | 33 |
1 files changed, 33 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 | ||