|
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 | +# 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. |
10 | 9 |
|
11 | 10 | - name: Check if zuul_vars.yaml file is available |
12 | 11 | ansible.builtin.stat: |
13 | 12 | path: "{{ ansible_user_dir }}/configs/zuul_vars.yaml" |
14 | 13 | register: _current_zuul_vars |
15 | 14 |
|
16 | | -- name: Overwrite reproducer-variables.yml when PreMetal used |
| 15 | +- name: Merge current vars into reproducer-variables.yml |
17 | 16 | when: _current_zuul_vars.stat.exists |
18 | 17 | 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 | + }} |
21 | 43 | 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 |
23 | 51 | ansible.builtin.fetch: |
24 | 52 | src: "{{ cifmw_basedir }}/parameters/reproducer-variables.yml" |
25 | | - dest: "{{ temp_reproducer_var_path }}" |
| 53 | + dest: "{{ _temp_stale }}" |
26 | 54 | flat: true |
27 | 55 | delegate_to: controller-0 |
28 | 56 | no_log: "{{ cifmw_nolog | default(true) | bool }}" |
29 | 57 |
|
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 |
31 | 66 | become: true |
32 | 67 | ansible.builtin.copy: |
33 | 68 | src: merge_yaml_override.py |
34 | 69 | dest: /usr/local/bin/merge_yaml_override |
35 | 70 | mode: "0755" |
36 | 71 |
|
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 }} |
43 | 79 | no_log: "{{ cifmw_nolog | default(true) | bool }}" |
44 | 80 |
|
45 | 81 | - name: Merge extra variable files into reproducer-variables.yml |
46 | 82 | 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 }} |
54 | 89 | loop: "{{ extra_variable_files }}" |
55 | 90 | loop_control: |
56 | 91 | loop_var: extra_variable_file |
57 | 92 | label: "{{ extra_variable_file | basename }}" |
58 | 93 | no_log: "{{ cifmw_nolog | default(true) | bool }}" |
59 | 94 |
|
60 | | - - name: Write back merged reproducer-variables.yml |
| 95 | + - name: Write merged reproducer-variables.yml back to controller-0 |
61 | 96 | ansible.builtin.copy: |
62 | | - src: "{{ temp_merged_reproducer_var_path }}" |
| 97 | + src: "{{ _temp_merged }}" |
63 | 98 | dest: "{{ cifmw_basedir }}/parameters/reproducer-variables.yml" |
64 | 99 | mode: "0664" |
65 | 100 | backup: true |
66 | | - no_log: "{{ cifmw_nolog | default(true) | bool }}" |
67 | 101 | delegate_to: controller-0 |
| 102 | + no_log: "{{ cifmw_nolog | default(true) | bool }}" |
68 | 103 |
|
69 | | - - name: Overwrite custom-params.yml |
| 104 | + - name: Update custom-params.yml on controller-0 |
70 | 105 | ansible.builtin.copy: |
71 | | - src: "{{ temp_merged_reproducer_var_path }}" |
| 106 | + src: "{{ _temp_merged }}" |
72 | 107 | dest: "{{ cifmw_basedir }}/artifacts/parameters/custom-params.yml" |
73 | 108 | mode: "0664" |
74 | | - no_log: "{{ cifmw_nolog | default(true) | bool }}" |
75 | 109 | 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