aboutsummaryrefslogtreecommitdiffhomepage
path: root/tasks/keys.yml
blob: 7ca09042383c83d2232d9c0ac8b7ca33fede62bb (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
31
32
33
34
---
- name: Set scope variables
  set_fact:
    rundeck_keys_base_path: "{{ rundeck_keys_scoped_by_project | default(true) | ternary('project/' + rundeck_project + '/' + rundeck_keys_group_path, rundeck_keys_group_path) }}"
  vars:
    group_name: "{{ rundeck_jobs_group | default('') }}"
    rundeck_keys_group_path: "{{ rundeck_keys_scoped_by_group | default((group_name|length) > 0) | ternary(group_name, '') }}"

- name: Include rundeck key
  include_tasks: key.yml
  with_items: "{{ rundeck_jobs_keys }}"

- name: Get all stored keys
  script:
    cmd: "{{ role_path }}/files/fetch_keys.sh {{ rundeck_api_url }}/{{ rundeck_api_version }} {{ rundeck_api_token }} keys/{{ rundeck_keys_base_path }}"
  register: rundeck_existing_keys
  when: rundeck_remove_missing_keys

- name: "Prepare list of keys to remove"
  set_fact:
    rundeck_existing_keys: "{{ rundeck_existing_keys.stdout_lines | list }}"
    rundeck_known_keys: "{{ rundeck_jobs_keys | map(attribute='path') | list }}"
  when: rundeck_remove_missing_keys

- name: "Remove jobs not declared"
  uri:
    url: "{{ rundeck_api_url }}/{{ rundeck_api_version }}/storage/keys/{{ rundeck_keys_base_path }}/{{ item }}"
    method: DELETE
    headers:
      Accept: application/json
      X-Rundeck-Auth-Token: "{{ rundeck_api_token }}"
    status_code: [204, 404]
  with_items: "{{ rundeck_existing_keys | difference(rundeck_known_keys) }}"
  when: rundeck_remove_missing_keys