diff options
author | Gaƫtan <36162164+gaetanfl@users.noreply.github.com> | 2018-09-12 15:54:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-12 15:54:31 +0200 |
commit | 56d88d5730d457ac24f9aa373b71588b433f4196 (patch) | |
tree | 28464600357b9c6e755f23d3afb32371f3f51bac /tasks/rundeck.yml | |
parent | 1af6a8441cbbe29f8c30b1279400d86f28651912 (diff) | |
parent | 73fc6fec8fb5dd844fe8165061db2a82153900d9 (diff) | |
download | ansible-rundeck-jobs-56d88d5730d457ac24f9aa373b71588b433f4196.tar.gz ansible-rundeck-jobs-56d88d5730d457ac24f9aa373b71588b433f4196.tar.zst ansible-rundeck-jobs-56d88d5730d457ac24f9aa373b71588b433f4196.zip |
Merge pull request #1 from gaetanfl/first_versionv0.1
first working version
Diffstat (limited to 'tasks/rundeck.yml')
-rw-r--r-- | tasks/rundeck.yml | 47 |
1 files changed, 47 insertions, 0 deletions
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 | ||