diff options
-rw-r--r-- | README.md | 49 | ||||
-rw-r--r-- | ansible.cfg | 2 | ||||
-rw-r--r-- | defaults/main.yml | 3 | ||||
-rw-r--r-- | handlers/main.yml | 2 | ||||
-rw-r--r-- | meta/main.yml | 57 | ||||
-rw-r--r-- | requirements.txt | 1 | ||||
-rw-r--r-- | tasks/main.yml | 5 | ||||
-rw-r--r-- | tasks/rundeck.yml | 47 | ||||
-rw-r--r-- | tests/inventory | 2 | ||||
-rw-r--r-- | tests/test.yml | 8 | ||||
-rw-r--r-- | vars/main.yml | 2 |
11 files changed, 176 insertions, 2 deletions
@@ -1,2 +1,47 @@ | |||
1 | # ansible-rundeck-jobs | 1 | Rundeck jobs |
2 | Synchronize rundeck jobs from a dir with a rundeck project | 2 | ========= |
3 | |||
4 | This role synchronize a directory containing yaml definition of jobs with a rundeck project | ||
5 | |||
6 | Requirements | ||
7 | ------------ | ||
8 | |||
9 | * `jmespath` python module | ||
10 | |||
11 | Role Variables | ||
12 | -------------- | ||
13 | |||
14 | * `rundeck_jobs_path` path of the directory containing the job definition (mandatory). | ||
15 | * `rundeck_project` name of the rundeck project (mandatory). | ||
16 | * `rundeck_api_url` base url of api (mandatory). | ||
17 | * `rundeck_api_token` the authentification token (mandatory). | ||
18 | * `rundeck_api_version` api version supported by rundeck server. Default to 26. | ||
19 | * `rundeck_remove_missing` Whether to delete jobs present in rundeck and not in file. Defaults to true. | ||
20 | |||
21 | Dependencies | ||
22 | ------------ | ||
23 | |||
24 | None | ||
25 | |||
26 | Example Playbook | ||
27 | ---------------- | ||
28 | |||
29 | Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: | ||
30 | |||
31 | - hosts: servers | ||
32 | vars: | ||
33 | rundeck_api_url: rundeck.example.com | ||
34 | rundeck_project: test | ||
35 | rundeck_jobs_path: /tmp/rundeck-jobs | ||
36 | roles: | ||
37 | - rundeck-jobs | ||
38 | |||
39 | License | ||
40 | ------- | ||
41 | |||
42 | TBD | ||
43 | |||
44 | Author Information | ||
45 | ------------------ | ||
46 | |||
47 | FretLink, Love and Truck | ||
diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..6462621 --- /dev/null +++ b/ansible.cfg | |||
@@ -0,0 +1,2 @@ | |||
1 | [defaults] | ||
2 | roles_path=../ | ||
diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..87958ec --- /dev/null +++ b/defaults/main.yml | |||
@@ -0,0 +1,3 @@ | |||
1 | --- | ||
2 | rundeck_api_version: 26 | ||
3 | rundeck_remove_missing: true | ||
diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..0cdf3ee --- /dev/null +++ b/handlers/main.yml | |||
@@ -0,0 +1,2 @@ | |||
1 | --- | ||
2 | # handlers file for ansible-rundeck-jobs \ No newline at end of file | ||
diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..0e695af --- /dev/null +++ b/meta/main.yml | |||
@@ -0,0 +1,57 @@ | |||
1 | galaxy_info: | ||
2 | author: FretLink | ||
3 | description: Love and Truck | ||
4 | company: FretLink | ||
5 | |||
6 | # If the issue tracker for your role is not on github, uncomment the | ||
7 | # next line and provide a value | ||
8 | # issue_tracker_url: http://example.com/issue/tracker | ||
9 | |||
10 | # Some suggested licenses: | ||
11 | # - BSD (default) | ||
12 | # - MIT | ||
13 | # - GPLv2 | ||
14 | # - GPLv3 | ||
15 | # - Apache | ||
16 | # - CC-BY | ||
17 | license: TBD | ||
18 | |||
19 | min_ansible_version: 2.5 | ||
20 | |||
21 | # If this a Container Enabled role, provide the minimum Ansible Container version. | ||
22 | # min_ansible_container_version: | ||
23 | |||
24 | # Optionally specify the branch Galaxy will use when accessing the GitHub | ||
25 | # repo for this role. During role install, if no tags are available, | ||
26 | # Galaxy will use this branch. During import Galaxy will access files on | ||
27 | # this branch. If Travis integration is configured, only notifications for this | ||
28 | # branch will be accepted. Otherwise, in all cases, the repo's default branch | ||
29 | # (usually master) will be used. | ||
30 | #github_branch: | ||
31 | |||
32 | # | ||
33 | # platforms is a list of platforms, and each platform has a name and a list of versions. | ||
34 | # | ||
35 | # platforms: | ||
36 | # - name: Fedora | ||
37 | # versions: | ||
38 | # - all | ||
39 | # - 25 | ||
40 | # - name: SomePlatform | ||
41 | # versions: | ||
42 | # - all | ||
43 | # - 1.0 | ||
44 | # - 7 | ||
45 | # - 99.99 | ||
46 | |||
47 | galaxy_tags: [] | ||
48 | # List tags for your role here, one per line. A tag is a keyword that describes | ||
49 | # and categorizes the role. Users find roles by searching for tags. Be sure to | ||
50 | # remove the '[]' above, if you add tags to this list. | ||
51 | # | ||
52 | # NOTE: A tag is limited to a single word comprised of alphanumeric characters. | ||
53 | # Maximum 20 tags per role. | ||
54 | |||
55 | dependencies: [] | ||
56 | # List your role dependencies here, one per line. Be sure to remove the '[]' above, | ||
57 | # if you add dependencies to this list. | ||
diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..45c1e03 --- /dev/null +++ b/requirements.txt | |||
@@ -0,0 +1 @@ | |||
jmespath | |||
diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..3d41031 --- /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-jobs | ||
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 | ||
diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/tests/inventory | |||
@@ -0,0 +1,2 @@ | |||
1 | localhost | ||
2 | |||
diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..25ef811 --- /dev/null +++ b/tests/test.yml | |||
@@ -0,0 +1,8 @@ | |||
1 | --- | ||
2 | - hosts: localhost | ||
3 | roles: | ||
4 | - role: ansible-rundeck-jobs | ||
5 | rundeck_api_url: https://rundeck.example.org | ||
6 | rundeck_project: Test | ||
7 | rundeck_api_token: token | ||
8 | rundeck_jobs_path: tests/rundeck_files | ||
diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..add68e1 --- /dev/null +++ b/vars/main.yml | |||
@@ -0,0 +1,2 @@ | |||
1 | --- | ||
2 | # vars file for ansible-rundeck-jobs \ No newline at end of file | ||