]> git.immae.eu Git - github/fretlink/ansible-rundeck-jobs.git/blob - tasks/key.yml
Add an option to remove existing keys that are not declared in ansible
[github/fretlink/ansible-rundeck-jobs.git] / tasks / key.yml
1 ---
2 - name: Build scoped path
3 set_fact:
4 rundeck_key_full_path: "{{ rundeck_keys_base_path }}/{{ item.path }}"
5
6 - name: Check key existence
7 uri:
8 url: "{{ rundeck_api_url }}/{{ rundeck_api_version }}/storage/keys/{{ rundeck_key_full_path }}"
9 method: GET
10 headers:
11 Accept: application/json
12 X-Rundeck-Auth-Token: "{{ rundeck_api_token }}"
13 status_code: [200, 404]
14 register: rundeck_existing_key
15
16 - name: Set method
17 set_fact:
18 rundeck_key_uri_method: "{{ (rundeck_existing_key.status == 404) | ternary('POST', 'PUT') }}"
19
20 - name: Import key
21 uri:
22 url: "{{ rundeck_api_url }}/{{ rundeck_api_version }}/storage/keys/{{ rundeck_key_full_path }}"
23 method: "{{ rundeck_key_uri_method }}"
24 headers:
25 Accept: application/json
26 Content-Type: "{{ item.type }}"
27 X-Rundeck-Auth-Token: "{{ rundeck_api_token }}"
28 status_code: [200, 201]
29 body: "{{ item.value }}"
30 body_format: raw