blob: 1250d24b9a631f98424bca183f1c8217d5941f8b (
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
- name: Create rundeck file list
find:
path: "{{ rundeck_jobs_path }}"
patterns: "*.yaml,*.yml"
delegate_to: localhost
register: rundeck_jobs_files
- name: Create rundeck jobs
uri:
url: "{{rundeck_api_url }}/{{rundeck_api_version}}/project/{{ rundeck_project }}/jobs/import"
method: POST
return_content: true
body_format: raw
body: fileformat=yaml&dupeOption=update&xmlBatch={{ lookup('file', item.path) | urlencode }}
headers:
Accept: application/json
Content-Type: application/x-www-form-urlencoded; charset=utf-8
X-Rundeck-Auth-Token: "{{ rundeck_api_token }}"
register: rundeck_create_jobs
with_items: "{{ rundeck_jobs_files.files}}"
- name: Check if a job failed
fail:
msg: "Job defined in {{ file }} has failed with message: {{ message }}"
with_items: "{{ rundeck_create_jobs.results }}"
loop_control:
label: "{{ item.item.path }}"
vars:
file: "{{ item.item.path }}"
message: "{{ item.json.failed }}"
when: item.json.failed|length > 0
ignore_errors: "{{ rundeck_ignore_creation_error }}"
- name: Get all jobs
uri:
url: "{{rundeck_api_url }}/{{rundeck_api_version}}/project/{{ rundeck_project }}/jobs?groupPathExact={{ rundeck_jobs_group | default(rundeck_empty_group_path) }}"
method: GET
headers:
Accept: application/json
X-Rundeck-Auth-Token: "{{ rundeck_api_token }}"
vars:
rundeck_empty_group_path: ''
register: rundeck_existing_jobs
when: rundeck_remove_missing
- name: "Prepare list of jobs to remove"
set_fact:
rundeck_created_ids: "{{ rundeck_create_jobs.results | map(attribute='json') | map('json_query','succeeded[*].id') | flatten | list }}"
rundeck_jobs_ids: "{{ rundeck_existing_jobs_list | map(attribute='id') | list }}"
vars:
rundeck_existing_jobs_list_null: "{{ rundeck_existing_jobs.json | selectattr('group', 'none') | list }}"
rundeck_existing_jobs_list: "{{ rundeck_jobs_group | default(false) | ternary(rundeck_existing_jobs.json, rundeck_existing_jobs_list_null) }}"
when: rundeck_remove_missing
- name: "Remove jobs not in the directory"
uri:
url: "{{rundeck_api_url }}/{{rundeck_api_version}}/job/{{ item }}"
method: DELETE
headers:
Accept: application/json
X-Rundeck-Auth-Token: "{{ rundeck_api_token }}"
status_code: [204]
with_items: "{{ rundeck_jobs_ids | difference(rundeck_created_ids) }}"
when: rundeck_remove_missing
|