Skip to content

Commit

Permalink
Extra variables for workflow job templates and job templates (#854)
Browse files Browse the repository at this point in the history
* feat: add variables related to job templates of workflow and related to project of job template

* fix: removing brackets

* Remove discussions link

* fix: remove trailing spaces

* fix: missing new line

* fix: remove trailing spaces part2

* misc: removing variables, allowing to export job templates and project related to workflow

* fix: trailing spaces

* fix: trailing spaces part2

* feat: add variable to control if related objects should be exported

* fix: missing README entry

* misc: change default behaviour

* misc: change task name to proper

* Update export_related_objects explanation

---------

Co-authored-by: Ivan Aragonés Muniesa <26822043+ivarmu@users.noreply.github.com>
Co-authored-by: Przemyslaw Kalitowski <przemyslaw@kalitowski.com>
Co-authored-by: adonisgarciac <71078987+adonisgarciac@users.noreply.github.com>
Co-authored-by: David Danielsson <djdanielsson@users.noreply.github.com>
  • Loading branch information
5 people committed Aug 7, 2024
1 parent c966615 commit 4c08f56
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/filetree_create_extra_variables.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- filetree_create able to export single worfklow with related job_templates and projects
1 change: 1 addition & 0 deletions roles/filetree_create/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The following variables are required for that role to work properly:
| `show_encrypted` | N/A | no | bool | Whether to remove the string '\$encrypted\$' in credentials output (not the actual credential value) |
| `omit_id` | N/A | no | bool | Whether to create output files without objects id.|
| `organization`| N/A | no | str | Default organization for all objects that have not been set in the source controller.|
| `export_related_objects` | False | no | bool | Whether to export related objects (job templates related to certain workflows and the projects associated with these job templates) when a single JT or a single WFJT are being exported. |

## Dependencies

Expand Down
1 change: 1 addition & 0 deletions roles/filetree_create/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ output_path: "/tmp/filetree_output"

# Maximum number of objects to return from the list. If a list view returns more an max_objects an exception will be raised
query_controller_api_max_objects: 10000
export_related_objects: false

controller_configuration_filetree_create_secure_logging: "{{ controller_configuration_secure_logging | default('false') }}"

Expand Down
7 changes: 7 additions & 0 deletions roles/filetree_create/tasks/job_templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
order_by: 'organization,id'
no_log: "{{ controller_configuration_filetree_create_secure_logging }}"

- name: "Export project related to job_template"
when: job_template_id is defined and project_id is not defined and (export_related_objects is defined and export_related_objects)
ansible.builtin.include_tasks: "projects.yml"
vars:
project_id: "job_templates_lookvar[0]['summary_fields']['project']['id'] }}"
no_log: "{{ controller_configuration_filetree_create_secure_logging }}"

- name: "Block for to generate flatten output"
when:
- flatten_output is defined
Expand Down
20 changes: 20 additions & 0 deletions roles/filetree_create/tasks/workflow_job_templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@
order_by: 'organization,id'
no_log: "{{ controller_configuration_filetree_create_secure_logging }}"

- name: "Block for exporting the related job templates"
when: workflow_job_template_id is defined and (export_related_objects is defined and export_related_objects)
block:
- name: "Get current Job Templates related to workflow from the API"
ansible.builtin.set_fact:
workflow_node_job_templates_lookvar: "{{ query(controller_api_plugin, workflow_job_templates_lookvar[0]['related']['workflow_nodes'],
host=controller_hostname, oauth_token=controller_oauthtoken, verify_ssl=controller_validate_certs,
return_all=true, max_objects=query_controller_api_max_objects)
}}"
no_log: "{{ controller_configuration_filetree_create_secure_logging }}"

- name: "Export job templates related to to workflow"
ansible.builtin.include_tasks: "job_templates.yml"
vars:
job_template_id: "{{ current_workflow_job_node_templates_asset_value['unified_job_template'] }}"
loop: "{{ workflow_node_job_templates_lookvar }}"
loop_control:
loop_var: current_workflow_job_node_templates_asset_value
no_log: "{{ controller_configuration_filetree_create_secure_logging }}"

- name: "Block for to generate flatten output"
when:
- flatten_output is defined
Expand Down

0 comments on commit 4c08f56

Please sign in to comment.