aboutsummaryrefslogtreecommitdiffhomepage
path: root/tasks/key.yml
blob: aa2b2d9382a8c66e2ae8f7c873bf05e6b9b8a04b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
---
- name: Build scoped path
  set_fact:
    rundeck_key_full_path: "{{ rundeck_keys_base_path }}/{{ item.path }}"

- name: Check key existence
  uri:
    url: "{{ rundeck_api_url }}/{{ rundeck_api_version }}/storage/keys/{{ rundeck_key_full_path }}"
    method: GET
    headers:
      Accept: application/json
      X-Rundeck-Auth-Token: "{{ rundeck_api_token }}"
    status_code: [200, 404]
  register: rundeck_existing_key

- name: Set method
  set_fact:
    rundeck_key_uri_method: "{{ (rundeck_existing_key.status == 404) | ternary('POST', 'PUT') }}"

- name: Import key
  uri:
    url: "{{ rundeck_api_url }}/{{ rundeck_api_version }}/storage/keys/{{ rundeck_key_full_path }}"
    method: "{{ rundeck_key_uri_method }}"
    headers:
      Accept: application/json
      Content-Type: "{{ item.type }}"
      X-Rundeck-Auth-Token: "{{ rundeck_api_token }}"
    status_code: [200, 201]
    body: "{{ item.value }}"
    body_format: raw