Skip to content

Commit 932b690

Browse files
committed
fix!: backwards compatibility with nested vars
Identified in `ansible-core < 2.15` nested vars will not be evaluated within templates that are loaded via `extends` or `includes`. The solution involves using `lookup('template', ...)` to ensure support dating back to `2.12`. Unfortunately `lookup` does not have access to the macro defined in `workflows.yml` nor does it inherit the `block_*_string` and `variable_*_string` from the `ansible.builtin.template` module as defined within `tasks/main.yml`. Also `lookup` does not support setting `block_*_string`` NOTE: this is not ideal due to the duplication and the changing of block/variable markers. Whilst low priority should be improved/replaced in the future.
1 parent a2dd70e commit 932b690

File tree

4 files changed

+58
-39
lines changed

4 files changed

+58
-39
lines changed

roles/github/templates/generic.yml.j2

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
<%- if github_environment_selector == 'single' -%>
1212
<%- set _ = github_kayobe_arguments.update({"KAYOBE_ENVIRONMENT": github_kayobe_environments | first}) -%>
1313
<%- endif -%>
14-
<% include "header.yml.j2" +%>
15-
14+
%% lookup('template', 'header.yml.j2') %%
1615
jobs:
1716
prepare-runner:
1817
uses: ./.github/workflows/prepare-runner.yml
Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
1-
name: %% format_file_name(workflow.file_name, is_title=true) %%
1+
{%- macro format_file_name(file_name, is_title=false, is_subtitle=false) -%}
2+
{%- set formatted_name = file_name | splitext | first -%}
3+
{%- if is_title -%}
4+
{%- set formatted_name = formatted_name | replace('-', ' ') | title | regex_replace('Vm','VM') -%}
5+
{%- endif -%}
6+
{%- if is_subtitle -%}
7+
{%- set formatted_name = formatted_name | replace('-', ' ') | capitalize | regex_replace('vm','VM') -%}
8+
{%- endif -%}
9+
{{ formatted_name }}
10+
{%- endmacro -%}
11+
name: {{ format_file_name(workflow.file_name, is_title=true) }}
212

313
on:
4-
<%- if workflow.trigger is defined +%>
5-
<%- for trigger_name in workflow.trigger.keys() +%>
6-
<%- if trigger_name == 'schedule' +%>
14+
{%- if workflow.trigger is defined +%}
15+
{%- for trigger_name in workflow.trigger.keys() +%}
16+
{%- if trigger_name == 'schedule' +%}
717
schedule:
8-
- cron: '%% workflow.trigger['schedule']['cron'] %%'
9-
<%- elif trigger_name == 'workflow_dispatch' +%>
18+
- cron: '{{ workflow.trigger['schedule']['cron'] }}'
19+
{%- elif trigger_name == 'workflow_dispatch' +%}
1020
workflow_dispatch:
11-
<%- if workflow.trigger['workflow_dispatch'] is not none +%>
21+
{%- if workflow.trigger['workflow_dispatch'] is not none +%}
1222
inputs:
13-
%% workflow.trigger['workflow_dispatch'] | flatten | join('') | indent(6) | trim %%
14-
<%- if github_environment_selector == 'input' +%>
15-
%% github_kayobe_environment_input | flatten | join('') | indent(6) | trim %%
16-
<%- endif +%>
17-
<%- endif +%>
18-
<%- endif +%>
19-
<%- endfor +%>
20-
<%- endif +%>
23+
{{ workflow.trigger['workflow_dispatch'] | flatten | join('') | indent(6) | trim }}
24+
{%- if github_environment_selector == 'input' +%}
25+
{{ github_kayobe_environment_input | flatten | join('') | indent(6) | trim }}
26+
{%- endif +%}
27+
{%- endif +%}
28+
{%- endif +%}
29+
{%- endfor +%}
30+
{%- endif -%}

roles/github/templates/run-tempest.yml.j2

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,7 @@
1212
<%- if github_environment_selector == 'single' -%>
1313
<%- set _ = github_kayobe_arguments.update({"KAYOBE_ENVIRONMENT": github_kayobe_environments[0] }) -%>
1414
<%- endif -%>
15-
name: %% format_file_name(workflow.file_name, is_title=true) %%
16-
17-
on:
18-
workflow_dispatch:
19-
inputs:
20-
test_suite:
21-
description: |
22-
The list of tests to run. This should be a name of file under
23-
.automation.conf/tempest/load-lists. Defaults to running
24-
default test suite.
25-
required: false
26-
default: 'default'
27-
type: choice
28-
options:
29-
%% workflow.test_suites | flatten | join('') | indent(10) | trim %%
30-
tempest_pattern:
31-
description: |
32-
Limit tests to this regex. Takes precedence over testSuite.
33-
<%- if github_environment_selector == 'input' +%>
34-
%% github_kayobe_environment_input | flatten | join('') | indent(6) | trim %%
35-
<%- endif +%>
36-
15+
%% lookup('template', 'tempest-header.yml.j2') %%
3716
jobs:
3817
prepare-runner:
3918
uses: ./.github/workflows/prepare-runner.yml
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{%- macro format_file_name(file_name, is_title=false, is_subtitle=false) -%}
2+
{%- set formatted_name = file_name | splitext | first -%}
3+
{%- if is_title -%}
4+
{%- set formatted_name = formatted_name | replace('-', ' ') | title | regex_replace('Vm','VM') -%}
5+
{%- endif -%}
6+
{%- if is_subtitle -%}
7+
{%- set formatted_name = formatted_name | replace('-', ' ') | capitalize | regex_replace('vm','VM') -%}
8+
{%- endif -%}
9+
{{ formatted_name }}
10+
{%- endmacro -%}
11+
name: {{ format_file_name(workflow.file_name, is_title=true) }}
12+
13+
on:
14+
workflow_dispatch:
15+
inputs:
16+
test_suite:
17+
description: |
18+
The list of tests to run. This should be a name of file under
19+
.automation.conf/tempest/load-lists. Defaults to running
20+
default test suite.
21+
required: false
22+
default: 'default'
23+
type: choice
24+
options:
25+
{{ workflow.test_suites | flatten | join('') | indent(10) | trim }}
26+
tempest_pattern:
27+
description: |
28+
Limit tests to this regex. Takes precedence over testSuite.
29+
{%- if github_environment_selector == 'input' +%}
30+
{{ github_kayobe_environment_input | flatten | join('') | indent(6) | trim }}
31+
{%- endif +%}

0 commit comments

Comments
 (0)