]> git.immae.eu Git - github/fretlink/ansible-rundeck-jobs.git/commitdiff
first working version
authorGaëtan Duchaussois <gaetan.duchaussois@fretlink.com>
Wed, 12 Sep 2018 08:39:01 +0000 (10:39 +0200)
committerGaëtan Duchaussois <gaetan.duchaussois@fretlink.com>
Wed, 12 Sep 2018 08:55:28 +0000 (10:55 +0200)
README.md
ansible.cfg [new file with mode: 0644]
defaults/main.yml [new file with mode: 0644]
handlers/main.yml [new file with mode: 0644]
meta/main.yml [new file with mode: 0644]
tasks/main.yml [new file with mode: 0644]
tasks/rundeck.yml [new file with mode: 0644]
tests/inventory [new file with mode: 0644]
tests/test.yml [new file with mode: 0644]
vars/main.yml [new file with mode: 0644]

index 9f78f6cd71ccc38ffab63765c754dbe57b03788a..2304d7515b7a5b70af8decd313f0de5e3cee596c 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,2 +1,43 @@
-# ansible-rundeck-jobs
-Synchronize  rundeck jobs from a dir with a rundeck project
+Rundeck jobs
+=========
+
+This role synchronize a directory containing yaml definition of jobs with a rundeck project
+
+Requirements
+------------
+
+None
+
+Role Variables
+--------------
+
+* `rundeck_jobs_path` path of the directory containing the job definition (mandatory).
+* `rundeck_project` name of the rundeck project (mandatory).
+* `rundeck_api_url` base url of api (mandatory).
+* `rundeck_api_token` the authentification token (mandatory).
+* `rundeck_api_version` api version supported by rundeck server. Default to 26.
+* `rundeck_remove_missing` Whether to delete jobs present in rundeck and not in file. Defaults to true.
+
+Dependencies
+------------
+
+None
+
+Example Playbook
+----------------
+
+Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
+
+    - hosts: servers
+      roles:
+         - { role: rundeck-jobs, rundeck_api_url: rundeck.example.com, rundeck_project: test, rundeck_jobs_path: /tmp/rundeck-jobs }
+
+License
+-------
+
+TBD
+
+Author Information
+------------------
+
+FretLink, Love and Truck
diff --git a/ansible.cfg b/ansible.cfg
new file mode 100644 (file)
index 0000000..6462621
--- /dev/null
@@ -0,0 +1,2 @@
+[defaults]
+roles_path=../
diff --git a/defaults/main.yml b/defaults/main.yml
new file mode 100644 (file)
index 0000000..87958ec
--- /dev/null
@@ -0,0 +1,3 @@
+---
+rundeck_api_version: 26
+rundeck_remove_missing: true
diff --git a/handlers/main.yml b/handlers/main.yml
new file mode 100644 (file)
index 0000000..0cdf3ee
--- /dev/null
@@ -0,0 +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 (file)
index 0000000..0e695af
--- /dev/null
@@ -0,0 +1,57 @@
+galaxy_info:
+  author: FretLink
+  description: Love and Truck
+  company: FretLink
+
+  # If the issue tracker for your role is not on github, uncomment the
+  # next line and provide a value
+  # issue_tracker_url: http://example.com/issue/tracker
+
+  # Some suggested licenses:
+  # - BSD (default)
+  # - MIT
+  # - GPLv2
+  # - GPLv3
+  # - Apache
+  # - CC-BY
+  license: TBD
+
+  min_ansible_version: 2.5
+
+  # If this a Container Enabled role, provide the minimum Ansible Container version.
+  # min_ansible_container_version:
+
+  # Optionally specify the branch Galaxy will use when accessing the GitHub
+  # repo for this role. During role install, if no tags are available,
+  # Galaxy will use this branch. During import Galaxy will access files on
+  # this branch. If Travis integration is configured, only notifications for this
+  # branch will be accepted. Otherwise, in all cases, the repo's default branch
+  # (usually master) will be used.
+  #github_branch:
+
+  #
+  # platforms is a list of platforms, and each platform has a name and a list of versions.
+  #
+  # platforms:
+  # - name: Fedora
+  #   versions:
+  #   - all
+  #   - 25
+  # - name: SomePlatform
+  #   versions:
+  #   - all
+  #   - 1.0
+  #   - 7
+  #   - 99.99
+
+  galaxy_tags: []
+    # List tags for your role here, one per line. A tag is a keyword that describes
+    # and categorizes the role. Users find roles by searching for tags. Be sure to
+    # remove the '[]' above, if you add tags to this list.
+    #
+    # NOTE: A tag is limited to a single word comprised of alphanumeric characters.
+    #       Maximum 20 tags per role.
+
+dependencies: []
+  # List your role dependencies here, one per line. Be sure to remove the '[]' above,
+  # if you add dependencies to this list.
diff --git a/tasks/main.yml b/tasks/main.yml
new file mode 100644 (file)
index 0000000..ece8bb9
--- /dev/null
@@ -0,0 +1,5 @@
+---
+- name: Include rundesk tasks
+  include_tasks: rundeck.yml
+  tags:
+    - rundeck
diff --git a/tasks/rundeck.yml b/tasks/rundeck.yml
new file mode 100644 (file)
index 0000000..642abd6
--- /dev/null
@@ -0,0 +1,47 @@
+- name: Create rundeck file list
+  find:
+    path: "{{ rundeck_jobs_path }}"
+    patterns: "*.yaml"
+  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: Get all jobs
+  uri:
+    url: "{{rundeck_api_url }}/{{rundeck_api_version}}/project/{{ rundeck_project }}/jobs"
+    method: GET
+    headers:
+      Accept: application/json
+      X-Rundeck-Auth-Token: "{{ rundeck_api_token }}"
+  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.json | map(attribute='id') | list }}"
+  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
diff --git a/tests/inventory b/tests/inventory
new file mode 100644 (file)
index 0000000..878877b
--- /dev/null
@@ -0,0 +1,2 @@
+localhost
+
diff --git a/tests/test.yml b/tests/test.yml
new file mode 100644 (file)
index 0000000..25ef811
--- /dev/null
@@ -0,0 +1,8 @@
+---
+- hosts: localhost
+  roles:
+    - role: ansible-rundeck-jobs
+      rundeck_api_url: https://rundeck.example.org 
+      rundeck_project: Test
+      rundeck_api_token: token 
+      rundeck_jobs_path: tests/rundeck_files 
diff --git a/vars/main.yml b/vars/main.yml
new file mode 100644 (file)
index 0000000..add68e1
--- /dev/null
@@ -0,0 +1,2 @@
+---
+# vars file for ansible-rundeck-jobs
\ No newline at end of file