|
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. At premetal pickup time the hypervisor has |
| 4 | +# all config files loaded as extra vars (via run-uni-reproducer.sh), |
| 5 | +# so hostvars contains every variable fully resolved -- no raw Jinja2. |
| 6 | +# |
| 7 | +# This is a straight overwrite using the same filter chain as the |
| 8 | +# bootstrap in configure_bm_ocp_controller.yml. The hypervisor's |
| 9 | +# pickup-time hostvars are a superset of what was dumped at bootstrap |
| 10 | +# (same config files plus any updates), so no merge is needed. |
10 | 11 |
|
11 | 12 | - name: Check if zuul_vars.yaml file is available |
12 | 13 | ansible.builtin.stat: |
13 | 14 | path: "{{ ansible_user_dir }}/configs/zuul_vars.yaml" |
14 | 15 | register: _current_zuul_vars |
15 | 16 |
|
16 | | -- name: Overwrite reproducer-variables.yml when PreMetal used |
| 17 | +- name: Update reproducer-variables.yml from resolved hostvars |
17 | 18 | when: _current_zuul_vars.stat.exists |
18 | 19 | vars: |
19 | | - temp_reproducer_var_path: /tmp/reproducer-variables.yml |
20 | | - temp_merged_reproducer_var_path: /tmp/merged-reproducer-variables.yml |
| 20 | + _filtered_vars: >- |
| 21 | + {{ |
| 22 | + hostvars[inventory_hostname] | default({}) | |
| 23 | + dict2items | |
| 24 | + selectattr('key', 'match', |
| 25 | + '^(pre|post|cifmw)_(?!install_yamls|devscripts).*') | |
| 26 | + rejectattr('key', 'equalto', 'cifmw_target_host') | |
| 27 | + rejectattr('key', 'equalto', 'cifmw_basedir') | |
| 28 | + rejectattr('key', 'equalto', 'cifmw_path') | |
| 29 | + rejectattr('key', 'equalto', 'cifmw_extras') | |
| 30 | + rejectattr('key', 'equalto', 'cifmw_openshift_kubeconfig') | |
| 31 | + rejectattr('key', 'equalto', 'cifmw_openshift_token') | |
| 32 | + rejectattr('key', 'equalto', 'cifmw_networking_env_definition') | |
| 33 | + rejectattr('key', 'match', '^cifmw_use_(?!lvms).*') | |
| 34 | + rejectattr('key', 'match', '^cifmw_reproducer.*') | |
| 35 | + rejectattr('key', 'match', '^cifmw_rhol.*') | |
| 36 | + rejectattr('key', 'match', '^cifmw_discover.*') | |
| 37 | + rejectattr('key', 'match', '^cifmw_libvirt_manager.*') | |
| 38 | + rejectattr('key', 'match', '^cifmw_manage_secrets_(pullsecret|citoken).*') | |
| 39 | + items2dict |
| 40 | + }} |
21 | 41 | block: |
22 | | - - name: Slurp reproducer-variables.yml to hypervisor |
23 | | - ansible.builtin.slurp: |
24 | | - src: "{{ cifmw_basedir }}/parameters/reproducer-variables.yml" |
25 | | - register: reproducer_original |
26 | | - delegate_to: controller-0 |
27 | | - no_log: "{{ cifmw_nolog | default(true) | bool }}" |
28 | | - |
29 | | - - name: Create temp file reproducer-variables.yml on hypervisor |
| 42 | + - name: Write reproducer-variables.yml to controller-0 |
30 | 43 | 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 }}" |
| 44 | + content: "{{ _filtered_vars | to_nice_yaml }}" |
60 | 45 | dest: "{{ cifmw_basedir }}/parameters/reproducer-variables.yml" |
61 | 46 | mode: "0664" |
62 | 47 | backup: true |
63 | | - no_log: "{{ cifmw_nolog | default(true) | bool }}" |
64 | 48 | delegate_to: controller-0 |
| 49 | + no_log: "{{ cifmw_nolog | default(true) | bool }}" |
65 | 50 |
|
66 | | - - name: Overwrite custom-params.yml |
| 51 | + - name: Write custom-params.yml to controller-0 |
67 | 52 | ansible.builtin.copy: |
68 | | - content: "{{ merged_reproducer_slurp.content | b64decode }}" |
| 53 | + content: "{{ _filtered_vars | to_nice_yaml }}" |
69 | 54 | dest: "{{ cifmw_basedir }}/artifacts/parameters/custom-params.yml" |
70 | 55 | mode: "0664" |
71 | | - no_log: "{{ cifmw_nolog | default(true) | bool }}" |
72 | 56 | delegate_to: controller-0 |
| 57 | + no_log: "{{ cifmw_nolog | default(true) | bool }}" |
0 commit comments