Mohammed Naser | 0a13cee | 2023-03-02 11:28:29 +0100 | [diff] [blame] | 1 | # Copyright (c) 2023 VEXXHOST, Inc. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
| 15 | - name: Reset the value of facts used for generating the configuration |
| 16 | run_once: true |
| 17 | ansible.builtin.set_fact: |
| 18 | _osa_config_diff_osa: {} |
| 19 | _osa_config_diff_atmosphere: {} |
| 20 | |
| 21 | - name: Slurp the configuration files for the service |
| 22 | run_once: true |
| 23 | delegate_to: "{{ hostvars[container]['physical_host'] }}" |
| 24 | ansible.builtin.slurp: |
| 25 | path: "{{ prefix }}{{ item.value }}" |
| 26 | register: _osa_config_diff_file |
| 27 | loop: "{{ osa_config_diff_config_files | dict2items }}" |
| 28 | vars: |
| 29 | container: "{{ groups[osa_config_diff_containers_group][0] }}" |
Mohammed Naser | 88b79f9 | 2023-03-02 13:22:32 +0100 | [diff] [blame] | 30 | prefix: "{% if hostvars[container].get('is_metal', False) == False %}/var/lib/lxc/{{ container }}/rootfs{% endif %}" |
Mohammed Naser | 0a13cee | 2023-03-02 11:28:29 +0100 | [diff] [blame] | 31 | |
| 32 | - name: Generate dictionary with all OpenStack Ansible configuration files (INI) |
| 33 | run_once: true |
Mohammed Naser | 20da681 | 2023-03-02 17:16:53 +0100 | [diff] [blame] | 34 | when: item.item.key.endswith('.conf') or item.item.key.endswith('.ini') |
Mohammed Naser | 0a13cee | 2023-03-02 11:28:29 +0100 | [diff] [blame] | 35 | ansible.builtin.set_fact: |
| 36 | _osa_config_diff_osa: "{{ _osa_config_diff_osa | combine({ item.item.key: item.content | b64decode | vexxhost.atmosphere.from_ini }) }}" |
| 37 | loop: "{{ _osa_config_diff_file.results }}" |
| 38 | loop_control: |
| 39 | label: "{{ item.item.key }}" |
| 40 | |
| 41 | - name: Generate dictionary with all OpenStack Ansible configuration files (YAML) |
| 42 | run_once: true |
| 43 | when: item.item.key.endswith('.yaml') |
| 44 | ansible.builtin.set_fact: |
| 45 | _osa_config_diff_osa: "{{ _osa_config_diff_osa | combine({ item.item.key: item.content | b64decode | from_yaml }) }}" |
| 46 | loop: "{{ _osa_config_diff_file.results }}" |
| 47 | loop_control: |
| 48 | label: "{{ item.item.key }}" |
| 49 | |
| 50 | - name: Generate configuration using Atmosphere |
| 51 | run_once: true |
| 52 | changed_when: false |
| 53 | kubernetes.core.helm_template: |
| 54 | chart_ref: "{{ osa_config_diff_chart_ref }}" |
| 55 | release_namespace: "{{ osa_config_diff_release_namespace }}" |
| 56 | release_values: "{{ osa_config_diff_release_values }}" |
| 57 | show_only: |
| 58 | - templates/configmap-etc.yaml |
| 59 | register: _osa_config_diff_helm |
| 60 | |
| 61 | - name: Generate dictionary with all Atmosphere configuration files (INI) |
| 62 | run_once: true |
Mohammed Naser | 5f18691 | 2023-03-04 20:03:39 +0100 | [diff] [blame] | 63 | when: item.key.endswith('.conf') or item.key.endswith('.ini') |
Mohammed Naser | 0a13cee | 2023-03-02 11:28:29 +0100 | [diff] [blame] | 64 | ansible.builtin.set_fact: |
| 65 | _osa_config_diff_atmosphere: "{{ _osa_config_diff_atmosphere | combine({item.key: _file_contents | vexxhost.atmosphere.from_ini }) }}" |
| 66 | loop: "{{ osa_config_diff_config_files | dict2items }}" |
| 67 | vars: |
| 68 | _file_contents: "{{ (_osa_config_diff_helm.stdout | from_yaml).data[item.key] | b64decode }}" |
| 69 | |
| 70 | - name: Generate dictionary with all Atmosphere configuration files (YAML) |
| 71 | run_once: true |
| 72 | when: item.key.endswith('.yaml') |
| 73 | ansible.builtin.set_fact: |
| 74 | _osa_config_diff_atmosphere: "{{ _osa_config_diff_atmosphere | combine({item.key: _file_contents | from_yaml }) }}" |
| 75 | loop: "{{ osa_config_diff_config_files | dict2items }}" |
| 76 | vars: |
| 77 | _file_contents: "{{ (_osa_config_diff_helm.stdout | from_yaml).data[item.key] | b64decode }}" |
| 78 | |
| 79 | - name: Print difference between Atmosphere and OpenStack Ansible |
| 80 | run_once: true |
| 81 | ansible.utils.fact_diff: |
| 82 | before: "{{ _osa_config_diff_osa }}" |
| 83 | after: "{{ _osa_config_diff_atmosphere }}" |
| 84 | |
| 85 | - name: Pause to verify the configuration |
| 86 | ansible.builtin.pause: |