Skip to content

Commit 6ed66b7

Browse files
przemkalitPrzemyslaw Kalitowski
and
Przemyslaw Kalitowski
authored
Fix issue with looping over always empty list (#920)
* fix: loop issue * fix: loop issue part2 * fix: missing brackets --------- Co-authored-by: Przemyslaw Kalitowski <przemyslaw@kalitowski.com>
1 parent 06c5ec9 commit 6ed66b7

File tree

9 files changed

+39
-44
lines changed

9 files changed

+39
-44
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
bugfixes:
3+
- Fixed issue with loops that were getting always empty list of objects

roles/filetree_create/tasks/applications.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,11 @@
5353
mode: '0755'
5454
vars:
5555
__path: "{{ output_path }}/{{ needed_path | regex_replace('/', '_') }}/applications"
56-
loop: >-
57-
{{ (applications_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') |
58-
map(attribute='organization') | map(attribute='name') | list | flatten | unique)
59-
+ ([default(organization)] if ((applications_lookvar | map(attribute='summary_fields')
60-
| selectattr('organization', 'undefined') | list | flatten) | length > 0) else [])
61-
}}
56+
loop: "{{ (applications_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') |
57+
map(attribute='organization') | map(attribute='name') | list | flatten | unique)
58+
+ ([organization] if ((applications_lookvar | map(attribute='summary_fields')
59+
| selectattr('organization', 'undefined') | list | flatten) | length > 0) else [])
60+
}}"
6261
loop_control:
6362
loop_var: needed_path
6463
label: "{{ __path }}"

roles/filetree_create/tasks/credentials.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,11 @@
5353
mode: '0755'
5454
vars:
5555
__path: "{{ output_path }}/{{ needed_path }}/credentials"
56-
loop: >-
57-
{{ (credentials_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') |
58-
map(attribute='organization') | map(attribute='name') | list | flatten | unique)
59-
+ ([(organization if organization is defined else 'ORGANIZATIONLESS')] if ((credentials_lookvar |
60-
map(attribute='summary_fields') | selectattr('organization', 'undefined') | list | flatten) | length > 0) else [])
61-
}}
56+
loop: "{{ (credentials_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') |
57+
map(attribute='organization') | map(attribute='name') | list | flatten | unique)
58+
+ ([organization] if ((credentials_lookvar |
59+
map(attribute='summary_fields') | selectattr('organization', 'undefined') | list | flatten) | length > 0) else [])
60+
}}"
6261
loop_control:
6362
loop_var: needed_path
6463
label: "{{ __path }}"

roles/filetree_create/tasks/job_templates.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,11 @@
8787
mode: '0755'
8888
vars:
8989
__path: "{{ output_path }}/{{ needed_path | regex_replace('/', '_') }}/job_templates"
90-
loop: >-
91-
{{ (job_templates_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') |
92-
map(attribute='organization') | map(attribute='name') | list | flatten | unique) +
93-
[organization] if (job_templates_lookvar | map(attribute='summary_fields') |
94-
selectattr('organization', 'undefined') | list | flatten | length > 0) else []
95-
}}
90+
loop: "{{ (job_templates_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') |
91+
map(attribute='organization') | map(attribute='name') | list | flatten | unique) +
92+
([organization] if ((job_templates_lookvar | map(attribute='summary_fields') |
93+
selectattr('organization', 'undefined') | list | flatten) | length > 0) else [])
94+
}}"
9695
loop_control:
9796
loop_var: needed_path
9897
label: "{{ __path }}"

roles/filetree_create/tasks/labels.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
vars:
5555
__path: "{{ output_path }}/{{ needed_path | regex_replace('/', '_') }}/labels"
5656
loop: "{{ (labels_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | map(attribute='organization') | map(attribute='name') | list | flatten | unique)
57-
+ (['ORGANIZATIONLESS'] if ((labels_lookvar | map(attribute='summary_fields') | selectattr('organization', 'undefined') | list | flatten) | length > 0) else [])
57+
+ ([organization] if ((labels_lookvar | map(attribute='summary_fields') | selectattr('organization', 'undefined') | list | flatten) | length > 0) else [])
5858
}}"
5959
loop_control:
6060
loop_var: needed_path

roles/filetree_create/tasks/notification_templates.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,11 @@
5050
mode: '0755'
5151
vars:
5252
__path: "{{ output_path }}/{{ needed_path | regex_replace('/', '_') }}/notification_templates"
53-
loop: >-
54-
{{ (notification_templates_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') |
55-
map(attribute='organization') | map(attribute='name') | list | flatten | unique) +
56-
[organization] if (notification_templates_lookvar | map(attribute='summary_fields') |
57-
selectattr('organization', 'undefined') | list | flatten | length > 0) else []
58-
}}
53+
loop: "{{ (notification_templates_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') |
54+
map(attribute='organization') | map(attribute='name') | list | flatten | unique) +
55+
([organization] if ((notification_templates_lookvar | map(attribute='summary_fields') |
56+
selectattr('organization', 'undefined') | list | flatten) | length > 0) else [])
57+
}}"
5958
loop_control:
6059
loop_var: needed_path
6160
label: "{{ __path }}"

roles/filetree_create/tasks/projects.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,11 @@
6464
mode: '0755'
6565
vars:
6666
__path: "{{ output_path }}/{{ needed_path | regex_replace('/', '_') }}/projects"
67-
loop: >-
68-
{{ (projects_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') |
69-
map(attribute='organization') | map(attribute='name') | list | flatten | unique) +
70-
[organization] if (projects_lookvar | map(attribute='summary_fields') |
71-
selectattr('organization', 'undefined') | list | flatten | length > 0) else []
72-
}}"
67+
loop: "{{ (projects_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') |
68+
map(attribute='organization') | map(attribute='name') | list | flatten | unique) +
69+
([organization] if ((projects_lookvar | map(attribute='summary_fields') |
70+
selectattr('organization', 'undefined') | list) | flatten | length > 0) else [])
71+
}}"
7372
loop_control:
7473
loop_var: needed_path
7574
label: "{{ __path }}"

roles/filetree_create/tasks/teams.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,11 @@
5353
mode: '0755'
5454
vars:
5555
__path: "{{ output_path }}/{{ needed_path | regex_replace('/', '_') }}/teams"
56-
loop: >-
57-
{{
58-
(teams_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') |
59-
map(attribute='organization') | map(attribute='name') | list | unique) +
60-
[organization] if (teams_lookvar | map(attribute='summary_fields') |
61-
selectattr('organization', 'undefined') | list | length > 0) else []
62-
}}
56+
loop: "{{ (teams_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') |
57+
map(attribute='organization') | map(attribute='name') | list | unique) +
58+
([organization] if ((teams_lookvar | map(attribute='summary_fields') |
59+
selectattr('organization', 'undefined') | list) | length > 0) else [])
60+
}}"
6361
loop_control:
6462
loop_var: needed_path
6563
label: "{{ __path }}"

roles/filetree_create/tasks/workflow_job_templates.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,11 @@
9090
mode: '0755'
9191
vars:
9292
__path: "{{ output_path }}/{{ needed_path | regex_replace('/', '_') }}/workflow_job_templates/"
93-
loop: >-
94-
{{ (workflow_job_templates_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') |
95-
map(attribute='organization') | map(attribute='name') | list | flatten | unique) +
96-
([organization] if ((workflow_job_templates_lookvar | map(attribute='summary_fields') |
97-
selectattr('organization', 'undefined') | list | flatten) | length > 0) else [])
98-
}}
93+
loop: "{{ (workflow_job_templates_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') |
94+
map(attribute='organization') | map(attribute='name') | list | flatten | unique) +
95+
([organization] if ((workflow_job_templates_lookvar | map(attribute='summary_fields') |
96+
selectattr('organization', 'undefined') | list | flatten) | length > 0) else [])
97+
}}"
9998
loop_control:
10099
loop_var: needed_path
101100
label: "{{ __path }}"

0 commit comments

Comments
 (0)