diff --git a/changelogs/fragments/filetree_create_loop_issue.yaml b/changelogs/fragments/filetree_create_loop_issue.yaml new file mode 100644 index 000000000..03f03f7ca --- /dev/null +++ b/changelogs/fragments/filetree_create_loop_issue.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - Fixed issue with loops that were getting always empty list of objects diff --git a/roles/filetree_create/tasks/applications.yml b/roles/filetree_create/tasks/applications.yml index 7dd8000a5..e53e58548 100644 --- a/roles/filetree_create/tasks/applications.yml +++ b/roles/filetree_create/tasks/applications.yml @@ -53,12 +53,11 @@ mode: '0755' vars: __path: "{{ output_path }}/{{ needed_path | regex_replace('/', '_') }}/applications" - loop: >- - {{ (applications_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | - map(attribute='organization') | map(attribute='name') | list | flatten | unique) - + ([default(organization)] if ((applications_lookvar | map(attribute='summary_fields') - | selectattr('organization', 'undefined') | list | flatten) | length > 0) else []) - }} + loop: "{{ (applications_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | + map(attribute='organization') | map(attribute='name') | list | flatten | unique) + + ([organization] if ((applications_lookvar | map(attribute='summary_fields') + | selectattr('organization', 'undefined') | list | flatten) | length > 0) else []) + }}" loop_control: loop_var: needed_path label: "{{ __path }}" diff --git a/roles/filetree_create/tasks/credentials.yml b/roles/filetree_create/tasks/credentials.yml index 9335ad1d0..5848c5fc7 100644 --- a/roles/filetree_create/tasks/credentials.yml +++ b/roles/filetree_create/tasks/credentials.yml @@ -53,12 +53,11 @@ mode: '0755' vars: __path: "{{ output_path }}/{{ needed_path }}/credentials" - loop: >- - {{ (credentials_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | - map(attribute='organization') | map(attribute='name') | list | flatten | unique) - + ([(organization if organization is defined else 'ORGANIZATIONLESS')] if ((credentials_lookvar | - map(attribute='summary_fields') | selectattr('organization', 'undefined') | list | flatten) | length > 0) else []) - }} + loop: "{{ (credentials_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | + map(attribute='organization') | map(attribute='name') | list | flatten | unique) + + ([organization] if ((credentials_lookvar | + map(attribute='summary_fields') | selectattr('organization', 'undefined') | list | flatten) | length > 0) else []) + }}" loop_control: loop_var: needed_path label: "{{ __path }}" diff --git a/roles/filetree_create/tasks/job_templates.yml b/roles/filetree_create/tasks/job_templates.yml index 6a97563aa..3f4190ed2 100644 --- a/roles/filetree_create/tasks/job_templates.yml +++ b/roles/filetree_create/tasks/job_templates.yml @@ -87,12 +87,11 @@ mode: '0755' vars: __path: "{{ output_path }}/{{ needed_path | regex_replace('/', '_') }}/job_templates" - loop: >- - {{ (job_templates_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | - map(attribute='organization') | map(attribute='name') | list | flatten | unique) + - [organization] if (job_templates_lookvar | map(attribute='summary_fields') | - selectattr('organization', 'undefined') | list | flatten | length > 0) else [] - }} + loop: "{{ (job_templates_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | + map(attribute='organization') | map(attribute='name') | list | flatten | unique) + + ([organization] if ((job_templates_lookvar | map(attribute='summary_fields') | + selectattr('organization', 'undefined') | list | flatten) | length > 0) else []) + }}" loop_control: loop_var: needed_path label: "{{ __path }}" diff --git a/roles/filetree_create/tasks/labels.yml b/roles/filetree_create/tasks/labels.yml index 10025581c..2eef9ac56 100644 --- a/roles/filetree_create/tasks/labels.yml +++ b/roles/filetree_create/tasks/labels.yml @@ -54,7 +54,7 @@ vars: __path: "{{ output_path }}/{{ needed_path | regex_replace('/', '_') }}/labels" loop: "{{ (labels_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | map(attribute='organization') | map(attribute='name') | list | flatten | unique) - + (['ORGANIZATIONLESS'] if ((labels_lookvar | map(attribute='summary_fields') | selectattr('organization', 'undefined') | list | flatten) | length > 0) else []) + + ([organization] if ((labels_lookvar | map(attribute='summary_fields') | selectattr('organization', 'undefined') | list | flatten) | length > 0) else []) }}" loop_control: loop_var: needed_path diff --git a/roles/filetree_create/tasks/notification_templates.yml b/roles/filetree_create/tasks/notification_templates.yml index f1122776e..4318c9e7d 100644 --- a/roles/filetree_create/tasks/notification_templates.yml +++ b/roles/filetree_create/tasks/notification_templates.yml @@ -50,12 +50,11 @@ mode: '0755' vars: __path: "{{ output_path }}/{{ needed_path | regex_replace('/', '_') }}/notification_templates" - loop: >- - {{ (notification_templates_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | - map(attribute='organization') | map(attribute='name') | list | flatten | unique) + - [organization] if (notification_templates_lookvar | map(attribute='summary_fields') | - selectattr('organization', 'undefined') | list | flatten | length > 0) else [] - }} + loop: "{{ (notification_templates_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | + map(attribute='organization') | map(attribute='name') | list | flatten | unique) + + ([organization] if ((notification_templates_lookvar | map(attribute='summary_fields') | + selectattr('organization', 'undefined') | list | flatten) | length > 0) else []) + }}" loop_control: loop_var: needed_path label: "{{ __path }}" diff --git a/roles/filetree_create/tasks/projects.yml b/roles/filetree_create/tasks/projects.yml index 1609d8f01..0c3358270 100644 --- a/roles/filetree_create/tasks/projects.yml +++ b/roles/filetree_create/tasks/projects.yml @@ -64,12 +64,11 @@ mode: '0755' vars: __path: "{{ output_path }}/{{ needed_path | regex_replace('/', '_') }}/projects" - loop: >- - {{ (projects_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | - map(attribute='organization') | map(attribute='name') | list | flatten | unique) + - [organization] if (projects_lookvar | map(attribute='summary_fields') | - selectattr('organization', 'undefined') | list | flatten | length > 0) else [] - }}" + loop: "{{ (projects_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | + map(attribute='organization') | map(attribute='name') | list | flatten | unique) + + ([organization] if ((projects_lookvar | map(attribute='summary_fields') | + selectattr('organization', 'undefined') | list) | flatten | length > 0) else []) + }}" loop_control: loop_var: needed_path label: "{{ __path }}" diff --git a/roles/filetree_create/tasks/teams.yml b/roles/filetree_create/tasks/teams.yml index 804be6e3b..5cc0079c4 100644 --- a/roles/filetree_create/tasks/teams.yml +++ b/roles/filetree_create/tasks/teams.yml @@ -53,13 +53,11 @@ mode: '0755' vars: __path: "{{ output_path }}/{{ needed_path | regex_replace('/', '_') }}/teams" - loop: >- - {{ - (teams_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | - map(attribute='organization') | map(attribute='name') | list | unique) + - [organization] if (teams_lookvar | map(attribute='summary_fields') | - selectattr('organization', 'undefined') | list | length > 0) else [] - }} + loop: "{{ (teams_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | + map(attribute='organization') | map(attribute='name') | list | unique) + + ([organization] if ((teams_lookvar | map(attribute='summary_fields') | + selectattr('organization', 'undefined') | list) | length > 0) else []) + }}" loop_control: loop_var: needed_path label: "{{ __path }}" diff --git a/roles/filetree_create/tasks/workflow_job_templates.yml b/roles/filetree_create/tasks/workflow_job_templates.yml index 72aa95d9a..1580184d1 100644 --- a/roles/filetree_create/tasks/workflow_job_templates.yml +++ b/roles/filetree_create/tasks/workflow_job_templates.yml @@ -90,12 +90,11 @@ mode: '0755' vars: __path: "{{ output_path }}/{{ needed_path | regex_replace('/', '_') }}/workflow_job_templates/" - loop: >- - {{ (workflow_job_templates_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | - map(attribute='organization') | map(attribute='name') | list | flatten | unique) + - ([organization] if ((workflow_job_templates_lookvar | map(attribute='summary_fields') | - selectattr('organization', 'undefined') | list | flatten) | length > 0) else []) - }} + loop: "{{ (workflow_job_templates_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | + map(attribute='organization') | map(attribute='name') | list | flatten | unique) + + ([organization] if ((workflow_job_templates_lookvar | map(attribute='summary_fields') | + selectattr('organization', 'undefined') | list | flatten) | length > 0) else []) + }}" loop_control: loop_var: needed_path label: "{{ __path }}"