diff options
author | Gaëtan Duchaussois <gaetan.duchaussois@fretlink.com> | 2018-09-12 10:39:01 +0200 |
---|---|---|
committer | Gaëtan Duchaussois <gaetan.duchaussois@fretlink.com> | 2018-09-12 10:55:28 +0200 |
commit | 030dd5c56410a21fc67e05e94f597c8bb255b7ee (patch) | |
tree | 369e71c5cc7e34d9a491bfe7a15bfab9fbfb742c /tasks | |
parent | 1af6a8441cbbe29f8c30b1279400d86f28651912 (diff) | |
download | ansible-rundeck-jobs-030dd5c56410a21fc67e05e94f597c8bb255b7ee.tar.gz ansible-rundeck-jobs-030dd5c56410a21fc67e05e94f597c8bb255b7ee.tar.zst ansible-rundeck-jobs-030dd5c56410a21fc67e05e94f597c8bb255b7ee.zip |
first working version
Diffstat (limited to 'tasks')
-rw-r--r-- | tasks/main.yml | 5 | ||||
-rw-r--r-- | tasks/rundeck.yml | 47 |
2 files changed, 52 insertions, 0 deletions
diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..ece8bb9 --- /dev/null +++ b/tasks/main.yml | |||
@@ -0,0 +1,5 @@ | |||
1 | --- | ||
2 | - name: Include rundesk tasks | ||
3 | include_tasks: rundeck.yml | ||
4 | tags: | ||
5 | - rundeck | ||
diff --git a/tasks/rundeck.yml b/tasks/rundeck.yml new file mode 100644 index 0000000..642abd6 --- /dev/null +++ b/tasks/rundeck.yml | |||
@@ -0,0 +1,47 @@ | |||
1 | - name: Create rundeck file list | ||
2 | find: | ||
3 | path: "{{ rundeck_jobs_path }}" | ||
4 | patterns: "*.yaml" | ||
5 | delegate_to: localhost | ||
6 | register: rundeck_jobs_files | ||
7 | |||
8 | - name: Create rundeck jobs | ||
9 | uri: | ||
10 | url: "{{rundeck_api_url }}/{{rundeck_api_version}}/project/{{ rundeck_project }}/jobs/import" | ||
11 | method: POST | ||
12 | return_content: true | ||
13 | body_format: raw | ||
14 | body: fileformat=yaml&dupeOption=update&xmlBatch={{ lookup('file', item.path) | urlencode }} | ||
15 | headers: | ||
16 | Accept: application/json | ||
17 | Content-Type: application/x-www-form-urlencoded; charset=utf-8 | ||
18 | X-Rundeck-Auth-Token: "{{ rundeck_api_token }}" | ||
19 | register: rundeck_create_jobs | ||
20 | with_items: "{{ rundeck_jobs_files.files}}" | ||
21 | |||
22 | - name: Get all jobs | ||
23 | uri: | ||
24 | url: "{{rundeck_api_url }}/{{rundeck_api_version}}/project/{{ rundeck_project }}/jobs" | ||
25 | method: GET | ||
26 | headers: | ||
27 | Accept: application/json | ||
28 | X-Rundeck-Auth-Token: "{{ rundeck_api_token }}" | ||
29 | register: rundeck_existing_jobs | ||
30 | when: rundeck_remove_missing | ||
31 | |||
32 | - name: "Prepare list of jobs to remove" | ||
33 | set_fact: | ||
34 | rundeck_created_ids: "{{ rundeck_create_jobs.results | map(attribute='json') | map('json_query','succeeded[*].id') | flatten | list }}" | ||
35 | rundeck_jobs_ids: "{{ rundeck_existing_jobs.json | map(attribute='id') | list }}" | ||
36 | when: rundeck_remove_missing | ||
37 | |||
38 | - name: "Remove jobs not in the directory" | ||
39 | uri: | ||
40 | url: "{{rundeck_api_url }}/{{rundeck_api_version}}/job/{{ item }}" | ||
41 | method: DELETE | ||
42 | headers: | ||
43 | Accept: application/json | ||
44 | X-Rundeck-Auth-Token: "{{ rundeck_api_token }}" | ||
45 | status_code: [204] | ||
46 | with_items: "{{ rundeck_jobs_ids | difference(rundeck_created_ids) }}" | ||
47 | when: rundeck_remove_missing | ||