Last active
April 5, 2024 12:28
-
-
Save b0tting/c24011f9ab023b74a19abdea9d70bc17 to your computer and use it in GitHub Desktop.
When working with the Rundeck key storage API you have a limited set of calls to work the tree with. I had a use case where I need to clear out a given path before syncing. This recursive ansible task walks the Rundeck key storag tree and deletes all items. Ansible will complain loudly about having to reuse the item loop_var, but you can safely …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: Calling out current path | |
debug: | |
msg: "Deleting path: {{ deleting_storage_path }}" | |
- name: Get path content | |
vars: | |
query_uri: "/api/{{ rundeck_api_version }}/storage/{{ deleting_storage_path }}/" | |
uri: | |
url: "{{ rundeck_url + (query_uri | urlencode) }}" | |
method: GET | |
headers: | |
X-Rundeck-Auth-Token: "{{ rundeck_token }}" | |
status_code: | |
- 200 | |
register: deleting_storage_result | |
- name: Delete items in current folder | |
when: item.type != "directory" | |
vars: | |
query_uri: "/api/{{ rundeck_api_version }}/storage/{{ item.path }}/" | |
uri: | |
url: "{{ rundeck_url + (query_uri | urlencode) }}" | |
method: DELETE | |
headers: | |
X-Rundeck-Auth-Token: "{{ rundeck_token }}" | |
status_code: | |
- 204 | |
loop: "{{ deleting_storage_result.json.resources }}" | |
- name: Recurse into every directory | |
when: item.type == "directory" | |
vars: | |
deleting_storage_path: "{{ item.path }}" | |
include_tasks: DeleteKeyStorageItems.yml | |
loop: "{{ deleting_storage_result.json.resources }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: "Delete Rundeck Key Storage trees" | |
hosts: localhost | |
vars: | |
rundeck_key_storage_path: "keys/delete_root_path" | |
rundeck_api_version: "45" | |
rundeck_url: "https://rundeck.example.com:8080" | |
rundeck_token: "<some rundeck token with key storage or admin access>" | |
tasks: | |
# Note! Recursive function | |
- name: "Clean out Rundeck key storage path" | |
vars: | |
deleting_storage_path: "{{ rundeck_key_storage_path }}" | |
include_tasks: DeleteKeyStorageItems.yml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment