Skip to content

Commit d6039bb

Browse files
committed
[reproducer] Merge all current vars into reproducer-variables
The premetal pickup phase overwrite_zuul_vars.yml previously merged only zuul_vars.yaml into the stale reproducer-variables.yml, missing scenario file changes (e.g. test skip lists in 05-tests.yaml). Dump current hostvars through the same filter as configure_controller.yml and deep-merge over the stale file, preserving premetal provision-time computed values. Generated-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Michael Burke <michburk@redhat.com>
1 parent f67ae9b commit d6039bb

1 file changed

Lines changed: 73 additions & 33 deletions

File tree

Lines changed: 73 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,115 @@
11
---
2-
# NOTE(dpawlik): Earlier, our idea was to dump vars as
3-
# it is roles/cifmw_setup/tasks/bootstrap.yml and read it,
4-
# then dump it and replace reproducer-variables.yml.
5-
# Normally it make sense, but since we dump zuul_vars in
6-
# run.yml, we don't need to make such combination, which is
7-
# more safe - on making host variable dump, some variables
8-
# might not be defined, so later we can have an issue like:
9-
# 'cifmw_discovered_image_url' is undefined.
2+
# Merge current job variables into the stale reproducer-variables.yml
3+
# that was written during PreMetal Phase 1 (bootstrap).
4+
#
5+
#
6+
# The _filtered_vars filter MUST stay in sync with the one in
7+
# configure_controller.yml. If they diverge, vars could be
8+
# included/excluded inconsistently between Phase 1 and Phase 2.
109

1110
- name: Check if zuul_vars.yaml file is available
1211
ansible.builtin.stat:
1312
path: "{{ ansible_user_dir }}/configs/zuul_vars.yaml"
1413
register: _current_zuul_vars
1514

16-
- name: Overwrite reproducer-variables.yml when PreMetal used
15+
- name: Merge current vars into reproducer-variables.yml
1716
when: _current_zuul_vars.stat.exists
1817
vars:
19-
temp_reproducer_var_path: /tmp/reproducer-variables.yml
20-
temp_merged_reproducer_var_path: /tmp/merged-reproducer-variables.yml
18+
_temp_dir: /tmp/premetal-var-merge
19+
_temp_stale: "{{ _temp_dir }}/reproducer-variables-stale.yml"
20+
_temp_current: "{{ _temp_dir }}/current-vars-dump.yml"
21+
_temp_merged: "{{ _temp_dir }}/reproducer-variables-merged.yml"
22+
# Same filter as configure_controller.yml -- keep in sync.
23+
_filtered_vars: >-
24+
{{
25+
hostvars[inventory_hostname] | default({}) |
26+
dict2items |
27+
selectattr('key', 'match',
28+
'^(pre|post|cifmw)_(?!install_yamls|devscripts).*') |
29+
rejectattr('key', 'equalto', 'cifmw_target_host') |
30+
rejectattr('key', 'equalto', 'cifmw_basedir') |
31+
rejectattr('key', 'equalto', 'cifmw_path') |
32+
rejectattr('key', 'equalto', 'cifmw_extras') |
33+
rejectattr('key', 'equalto', 'cifmw_openshift_kubeconfig') |
34+
rejectattr('key', 'equalto', 'cifmw_openshift_token') |
35+
rejectattr('key', 'equalto', 'cifmw_networking_env_definition') |
36+
rejectattr('key', 'match', '^cifmw_use_(?!lvms).*') |
37+
rejectattr('key', 'match', '^cifmw_reproducer.*') |
38+
rejectattr('key', 'match', '^cifmw_rhol.*') |
39+
rejectattr('key', 'match', '^cifmw_libvirt_manager.*') |
40+
rejectattr('key', 'match', '^cifmw_manage_secrets_(pullsecret|citoken).*') |
41+
items2dict
42+
}}
2143
block:
22-
- name: Fetch reproducer-variables.yml from controller-0
44+
- name: Create temp directory for merge workspace
45+
ansible.builtin.file:
46+
path: "{{ _temp_dir }}"
47+
state: directory
48+
mode: "0700"
49+
50+
- name: Fetch stale reproducer-variables.yml from controller-0
2351
ansible.builtin.fetch:
2452
src: "{{ cifmw_basedir }}/parameters/reproducer-variables.yml"
25-
dest: "{{ temp_reproducer_var_path }}"
53+
dest: "{{ _temp_stale }}"
2654
flat: true
2755
delegate_to: controller-0
2856
no_log: "{{ cifmw_nolog | default(true) | bool }}"
2957

30-
- name: Copy merge yamls script
58+
- name: Dump current hostvars through reproducer-variables filter
59+
ansible.builtin.copy:
60+
content: "{{ _filtered_vars | to_nice_yaml }}"
61+
dest: "{{ _temp_current }}"
62+
mode: "0644"
63+
no_log: "{{ cifmw_nolog | default(true) | bool }}"
64+
65+
- name: Copy merge script
3166
become: true
3267
ansible.builtin.copy:
3368
src: merge_yaml_override.py
3469
dest: /usr/local/bin/merge_yaml_override
3570
mode: "0755"
3671

37-
- name: Execute merge script
38-
ansible.builtin.shell: >
39-
python3 /usr/local/bin/merge_yaml_override
40-
{{ temp_reproducer_var_path }}
41-
{{ ansible_user_dir }}/configs/zuul_vars.yaml >
42-
{{ temp_merged_reproducer_var_path }}
72+
- name: Deep-merge current vars over stale reproducer-variables.yml
73+
ansible.builtin.command:
74+
cmd: >-
75+
python3 /usr/local/bin/merge_yaml_override
76+
{{ _temp_stale }}
77+
{{ _temp_current }}
78+
{{ _temp_merged }}
4379
no_log: "{{ cifmw_nolog | default(true) | bool }}"
4480

4581
- name: Merge extra variable files into reproducer-variables.yml
4682
when: extra_variable_files is defined
47-
ansible.builtin.shell: >
48-
python3 /usr/local/bin/merge_yaml_override
49-
{{ temp_merged_reproducer_var_path }}
50-
{{ extra_variable_file }} >
51-
{{ temp_merged_reproducer_var_path }}.tmp &&
52-
mv {{ temp_merged_reproducer_var_path }}.tmp
53-
{{ temp_merged_reproducer_var_path }}
83+
ansible.builtin.command:
84+
cmd: >-
85+
python3 /usr/local/bin/merge_yaml_override
86+
{{ _temp_merged }}
87+
{{ extra_variable_file }}
88+
{{ _temp_merged }}
5489
loop: "{{ extra_variable_files }}"
5590
loop_control:
5691
loop_var: extra_variable_file
5792
label: "{{ extra_variable_file | basename }}"
5893
no_log: "{{ cifmw_nolog | default(true) | bool }}"
5994

60-
- name: Write back merged reproducer-variables.yml
95+
- name: Write merged reproducer-variables.yml back to controller-0
6196
ansible.builtin.copy:
62-
src: "{{ temp_merged_reproducer_var_path }}"
97+
src: "{{ _temp_merged }}"
6398
dest: "{{ cifmw_basedir }}/parameters/reproducer-variables.yml"
6499
mode: "0664"
65100
backup: true
66-
no_log: "{{ cifmw_nolog | default(true) | bool }}"
67101
delegate_to: controller-0
102+
no_log: "{{ cifmw_nolog | default(true) | bool }}"
68103

69-
- name: Overwrite custom-params.yml
104+
- name: Update custom-params.yml on controller-0
70105
ansible.builtin.copy:
71-
src: "{{ temp_merged_reproducer_var_path }}"
106+
src: "{{ _temp_merged }}"
72107
dest: "{{ cifmw_basedir }}/artifacts/parameters/custom-params.yml"
73108
mode: "0664"
74-
no_log: "{{ cifmw_nolog | default(true) | bool }}"
75109
delegate_to: controller-0
110+
no_log: "{{ cifmw_nolog | default(true) | bool }}"
111+
112+
- name: Clean up temp merge workspace
113+
ansible.builtin.file:
114+
path: "{{ _temp_dir }}"
115+
state: absent

0 commit comments

Comments
 (0)