|
1 | 1 | --- |
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 | +# Update reproducer-variables.yml on controller-0 with the current |
| 3 | +# hypervisor hostvars, merged over the existing bootstrap dump. |
| 4 | +# |
| 5 | +# At premetal pickup time the hypervisor has all config files loaded |
| 6 | +# as extra vars (via run-uni-reproducer.sh), so hostvars contains |
| 7 | +# every config variable fully resolved, no raw jinja. |
| 8 | +# |
| 9 | +# The filter chain matches configure_bm_ocp_controller.yml, so |
| 10 | +# only (pre|post|cifmw)_ keys survive, minus hypervisor-specific |
| 11 | +# vars that must not reach controller-0. |
10 | 12 |
|
11 | 13 | - name: Check if zuul_vars.yaml file is available |
12 | 14 | ansible.builtin.stat: |
13 | 15 | path: "{{ ansible_user_dir }}/configs/zuul_vars.yaml" |
14 | 16 | register: _current_zuul_vars |
15 | 17 |
|
16 | | -- name: Overwrite reproducer-variables.yml when PreMetal used |
| 18 | +- name: Update reproducer-variables.yml from resolved hostvars |
17 | 19 | when: _current_zuul_vars.stat.exists |
18 | 20 | vars: |
19 | | - temp_reproducer_var_path: /tmp/reproducer-variables.yml |
20 | | - temp_merged_reproducer_var_path: /tmp/merged-reproducer-variables.yml |
| 21 | + _filtered_vars: >- |
| 22 | + {{ |
| 23 | + hostvars[inventory_hostname] | default({}) | |
| 24 | + dict2items | |
| 25 | + selectattr('key', 'match', |
| 26 | + '^(pre|post|cifmw)_(?!install_yamls|devscripts).*') | |
| 27 | + rejectattr('key', 'equalto', 'cifmw_target_host') | |
| 28 | + rejectattr('key', 'equalto', 'cifmw_basedir') | |
| 29 | + rejectattr('key', 'equalto', 'cifmw_path') | |
| 30 | + rejectattr('key', 'equalto', 'cifmw_extras') | |
| 31 | + rejectattr('key', 'equalto', 'cifmw_openshift_kubeconfig') | |
| 32 | + rejectattr('key', 'equalto', 'cifmw_openshift_token') | |
| 33 | + rejectattr('key', 'equalto', 'cifmw_networking_env_definition') | |
| 34 | + rejectattr('key', 'match', '^cifmw_use_(?!lvms).*') | |
| 35 | + rejectattr('key', 'match', '^cifmw_reproducer.*') | |
| 36 | + rejectattr('key', 'match', '^cifmw_rhol.*') | |
| 37 | + rejectattr('key', 'match', '^cifmw_discover.*') | |
| 38 | + rejectattr('key', 'match', '^cifmw_libvirt_manager.*') | |
| 39 | + rejectattr('key', 'match', '^cifmw_manage_secrets_(pullsecret|citoken).*') | |
| 40 | + items2dict |
| 41 | + }} |
21 | 42 | block: |
22 | | - - name: Slurp reproducer-variables.yml to hypervisor |
| 43 | + - name: Slurp existing reproducer-variables.yml from controller-0 |
23 | 44 | ansible.builtin.slurp: |
24 | 45 | src: "{{ cifmw_basedir }}/parameters/reproducer-variables.yml" |
25 | | - register: reproducer_original |
| 46 | + register: _existing_repro_vars |
26 | 47 | delegate_to: controller-0 |
27 | 48 | no_log: "{{ cifmw_nolog | default(true) | bool }}" |
28 | 49 |
|
29 | | - - name: Create temp file reproducer-variables.yml on hypervisor |
| 50 | + - name: Write merged reproducer-variables.yml to controller-0 |
| 51 | + vars: |
| 52 | + _merged: >- |
| 53 | + {{ (_existing_repro_vars.content | b64decode | |
| 54 | + from_yaml | default({})) | |
| 55 | + combine(_filtered_vars, recursive=True) }} |
30 | 56 | ansible.builtin.copy: |
31 | | - content: "{{ reproducer_original.content | b64decode }}" |
32 | | - dest: "{{ temp_reproducer_var_path }}" |
33 | | - mode: "0664" |
34 | | - no_log: "{{ cifmw_nolog | default(true) | bool }}" |
35 | | - |
36 | | - - name: Copy merge yamls script |
37 | | - become: true |
38 | | - ansible.builtin.copy: |
39 | | - src: merge_yaml_override.py |
40 | | - dest: /usr/local/bin/merge_yaml_override |
41 | | - mode: "0755" |
42 | | - |
43 | | - - name: Execute merge script |
44 | | - ansible.builtin.shell: > |
45 | | - python3 /usr/local/bin/merge_yaml_override |
46 | | - {{ temp_reproducer_var_path }} |
47 | | - {{ ansible_user_dir }}/configs/zuul_vars.yaml > |
48 | | - {{ temp_merged_reproducer_var_path }} |
49 | | - no_log: "{{ cifmw_nolog | default(true) | bool }}" |
50 | | - |
51 | | - - name: Slurp merged reproducer-variables.yml from hypervisor |
52 | | - ansible.builtin.slurp: |
53 | | - src: "{{ temp_merged_reproducer_var_path }}" |
54 | | - register: merged_reproducer_slurp |
55 | | - no_log: "{{ cifmw_nolog | default(true) | bool }}" |
56 | | - |
57 | | - - name: Write back merged reproducer-variables.yml |
58 | | - ansible.builtin.copy: |
59 | | - content: "{{ merged_reproducer_slurp.content | b64decode }}" |
| 57 | + content: "{{ _merged | to_nice_yaml }}" |
60 | 58 | dest: "{{ cifmw_basedir }}/parameters/reproducer-variables.yml" |
61 | 59 | mode: "0664" |
62 | 60 | backup: true |
63 | 61 | no_log: "{{ cifmw_nolog | default(true) | bool }}" |
64 | 62 | delegate_to: controller-0 |
65 | 63 |
|
66 | | - - name: Overwrite custom-params.yml |
| 64 | + - name: Write merged custom-params.yml to controller-0 |
| 65 | + vars: |
| 66 | + _merged: >- |
| 67 | + {{ (_existing_repro_vars.content | b64decode | |
| 68 | + from_yaml | default({})) | |
| 69 | + combine(_filtered_vars, recursive=True) }} |
67 | 70 | ansible.builtin.copy: |
68 | | - content: "{{ merged_reproducer_slurp.content | b64decode }}" |
| 71 | + content: "{{ _merged | to_nice_yaml }}" |
69 | 72 | dest: "{{ cifmw_basedir }}/artifacts/parameters/custom-params.yml" |
70 | 73 | mode: "0664" |
71 | 74 | no_log: "{{ cifmw_nolog | default(true) | bool }}" |
|
0 commit comments