|
| 1 | +--- |
| 2 | +# Copyright Red Hat, Inc. |
| 3 | +# All Rights Reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | +# not use this file except in compliance with the License. You may obtain |
| 7 | +# a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | +# License for the specific language governing permissions and limitations |
| 15 | +# under the License. |
| 16 | + |
| 17 | +# Master playbook to update OpenStack packages across all layers: |
| 18 | +# - Control plane containers |
| 19 | +# - EDPM compute containers |
| 20 | +# - EDPM compute node hosts |
| 21 | +# |
| 22 | +# Granular control via flags: |
| 23 | +# cifmw_fdp_update_container_images_update_control_plane_images: true/false |
| 24 | +# cifmw_fdp_update_container_images_update_edpm_images: true/false |
| 25 | +# cifmw_fdp_update_container_images_update_edpm_host_packages: true/false |
| 26 | +# |
| 27 | +# Usage Examples: |
| 28 | +# |
| 29 | +# 1. Update everything (default): |
| 30 | +# ansible-playbook playbooks/fdp_update.yml \ |
| 31 | +# -e cifmw_fdp_update_container_images_target_package=ovn24.03 \ |
| 32 | +# -e cifmw_fdp_update_container_images_repo_baseurl=http://example.com/repo/ |
| 33 | +# |
| 34 | +# 2. Update only control plane: |
| 35 | +# ansible-playbook playbooks/fdp_update.yml \ |
| 36 | +# -e cifmw_fdp_update_container_images_target_package=ovn24.03 \ |
| 37 | +# -e cifmw_fdp_update_container_images_repo_baseurl=http://example.com/repo/ \ |
| 38 | +# -e cifmw_fdp_update_container_images_update_edpm_images=false \ |
| 39 | +# -e cifmw_fdp_update_container_images_update_edpm_host_packages=false |
| 40 | +# |
| 41 | +# 3. Update only EDPM host packages: |
| 42 | +# ansible-playbook playbooks/fdp_update.yml \ |
| 43 | +# -e cifmw_fdp_update_container_images_target_package=openvswitch3.3 \ |
| 44 | +# -e cifmw_fdp_update_container_images_repo_baseurl=http://example.com/ovs-repo/ \ |
| 45 | +# -e cifmw_fdp_update_container_images_update_control_plane_images=false \ |
| 46 | +# -e cifmw_fdp_update_container_images_update_edpm_images=false |
| 47 | + |
| 48 | +- name: Update OpenStack packages across all layers |
| 49 | + hosts: "{{ cifmw_target_host | default('localhost') }}" |
| 50 | + gather_facts: true |
| 51 | + vars: |
| 52 | + # Control flags for what to update (can be overridden via -e) |
| 53 | + cifmw_fdp_update_container_images_update_edpm_images: true |
| 54 | + cifmw_fdp_update_container_images_update_edpm_host_packages: true |
| 55 | + |
| 56 | + pre_tasks: |
| 57 | + - name: Early playbook stop if disabled |
| 58 | + when: |
| 59 | + - not cifmw_fdp_update_enabled | default(false) | bool |
| 60 | + ansible.builtin.meta: end_play |
| 61 | + |
| 62 | + - name: Validate required variables are set |
| 63 | + ansible.builtin.assert: |
| 64 | + that: |
| 65 | + - cifmw_fdp_update_container_images_target_package is defined |
| 66 | + - cifmw_fdp_update_container_images_target_package | length > 0 |
| 67 | + - cifmw_fdp_update_container_images_repo_baseurl is defined |
| 68 | + - cifmw_fdp_update_container_images_repo_baseurl | length > 0 |
| 69 | + fail_msg: | |
| 70 | + Required variables are missing! |
| 71 | +
|
| 72 | + You must set: |
| 73 | + - cifmw_fdp_update_container_images_target_package: Name of the RPM package to update |
| 74 | + - cifmw_fdp_update_container_images_repo_baseurl: Repository base URL containing the updated package |
| 75 | +
|
| 76 | + Example: |
| 77 | + ansible-playbook playbooks/fdp_update.yml \ |
| 78 | + -e cifmw_fdp_update_container_images_target_package=ovn24.03 \ |
| 79 | + -e cifmw_fdp_update_container_images_repo_baseurl=http://example.com/repo/ |
| 80 | + success_msg: "Required variables validated successfully" |
| 81 | + |
| 82 | + - name: Display update configuration |
| 83 | + ansible.builtin.debug: |
| 84 | + msg: |
| 85 | + - "==============================================" |
| 86 | + - "OpenStack Package Update Configuration" |
| 87 | + - "==============================================" |
| 88 | + - "Target Package: {{ cifmw_fdp_update_container_images_target_package }}" |
| 89 | + - "Repository: {{ cifmw_fdp_update_container_images_repo_baseurl }}" |
| 90 | + - "" |
| 91 | + - "Update Control Flags:" |
| 92 | + - " Control Plane Images: {{ cifmw_fdp_update_container_images_update_control_plane_images | default(true) }}" |
| 93 | + - " EDPM Container Images: {{ cifmw_fdp_update_container_images_update_edpm_images | default(true) }}" |
| 94 | + - " EDPM Host Packages: {{ cifmw_fdp_update_container_images_update_edpm_host_packages | default(true) }}" |
| 95 | + - "" |
| 96 | + - "Namespace: {{ cifmw_fdp_update_container_images_namespace | default('openstack') }}" |
| 97 | + - "==============================================" |
| 98 | + |
| 99 | + - name: Setup hypervisor firewall for registry access |
| 100 | + become: true |
| 101 | + when: cifmw_fdp_update_setup_hypervisor_firewall | default(true) | bool |
| 102 | + block: |
| 103 | + - name: Allow traffic from osp_trunk to ocpbm (compute -> registry) |
| 104 | + ansible.builtin.command: # noqa: command-instead-of-module |
| 105 | + cmd: iptables -I FORWARD -i osp_trunk -o ocpbm -j ACCEPT |
| 106 | + register: _fdp_update_fw_rule1 |
| 107 | + failed_when: false |
| 108 | + changed_when: _fdp_update_fw_rule1.rc == 0 |
| 109 | + |
| 110 | + - name: Allow return traffic from ocpbm to osp_trunk (registry -> compute) |
| 111 | + ansible.builtin.command: # noqa: command-instead-of-module |
| 112 | + cmd: iptables -I FORWARD -i ocpbm -o osp_trunk -m state --state RELATED,ESTABLISHED -j ACCEPT |
| 113 | + register: _fdp_update_fw_rule2 |
| 114 | + failed_when: false |
| 115 | + changed_when: _fdp_update_fw_rule2.rc == 0 |
| 116 | + |
| 117 | + - name: Enable NAT for compute nodes to access registry |
| 118 | + ansible.builtin.command: # noqa: command-instead-of-module |
| 119 | + cmd: iptables -t nat -A POSTROUTING -s 192.168.122.0/24 -d 192.168.201.0/24 -o ocpbm -j MASQUERADE |
| 120 | + register: _fdp_update_nat_rule |
| 121 | + failed_when: false |
| 122 | + changed_when: _fdp_update_nat_rule.rc == 0 |
| 123 | + |
| 124 | + - name: Persist firewall rules |
| 125 | + ansible.builtin.shell: # noqa: command-instead-of-shell |
| 126 | + cmd: iptables-save > /etc/sysconfig/iptables |
| 127 | + when: _fdp_update_fw_rule1.changed or _fdp_update_fw_rule2.changed or _fdp_update_nat_rule.changed |
| 128 | + |
| 129 | + roles: |
| 130 | + # Update control plane container images |
| 131 | + - role: fdp_update_container_images |
| 132 | + when: cifmw_fdp_update_container_images_update_control_plane_images | default(true) | bool |
| 133 | + |
| 134 | + # Update EDPM (containers and host packages unified) |
| 135 | + - role: fdp_update_edpm |
| 136 | + vars: |
| 137 | + # Map old variables to new unified role |
| 138 | + cifmw_fdp_update_edpm_namespace: "{{ cifmw_fdp_update_container_images_namespace | default('openstack') }}" |
| 139 | + cifmw_fdp_update_edpm_repo_baseurl: "{{ cifmw_fdp_update_container_images_repo_baseurl }}" |
| 140 | + cifmw_fdp_update_edpm_containers_enabled: "{{ cifmw_fdp_update_container_images_update_edpm_images | default(true) | bool }}" |
| 141 | + cifmw_fdp_update_edpm_packages_enabled: "{{ cifmw_fdp_update_container_images_update_edpm_host_packages | default(true) | bool }}" |
| 142 | + when: >- |
| 143 | + (cifmw_fdp_update_container_images_update_edpm_images | default(true) | bool) or |
| 144 | + (cifmw_fdp_update_container_images_update_edpm_host_packages | default(true) | bool) |
| 145 | +
|
| 146 | + post_tasks: |
| 147 | + - name: Build status messages |
| 148 | + ansible.builtin.set_fact: |
| 149 | + _cifmw_fdp_update_cp_status: "{{ 'Updated' if (cifmw_fdp_update_container_images_update_control_plane_images | default(true) | bool) else 'Skipped' }}" |
| 150 | + _cifmw_fdp_update_edpm_images_status: "{{ 'Updated' if (cifmw_fdp_update_container_images_update_edpm_images | default(true) | bool) else 'Skipped' }}" |
| 151 | + _cifmw_fdp_update_edpm_packages_status: "{{ 'Service created' if (cifmw_fdp_update_container_images_update_edpm_host_packages | default(true) | bool) else 'Skipped' }}" |
| 152 | + _cifmw_fdp_update_edpm_enabled: "{{ (cifmw_fdp_update_container_images_update_edpm_images | default(true) | bool) or (cifmw_fdp_update_container_images_update_edpm_host_packages | default(true) | bool) }}" |
| 153 | + |
| 154 | + - name: Display completion summary |
| 155 | + ansible.builtin.debug: |
| 156 | + msg: |
| 157 | + - "==============================================" |
| 158 | + - "OpenStack Package Update Completed" |
| 159 | + - "==============================================" |
| 160 | + - "" |
| 161 | + - "Control plane containers: {{ _cifmw_fdp_update_cp_status }}" |
| 162 | + - "EDPM container images: {{ _cifmw_fdp_update_edpm_images_status }}" |
| 163 | + - "EDPM host packages: {{ _cifmw_fdp_update_edpm_packages_status }}" |
| 164 | + - "" |
| 165 | + - "Package: {{ cifmw_fdp_update_container_images_target_package }}" |
| 166 | + - "Repository: {{ cifmw_fdp_update_container_images_repo_baseurl }}" |
| 167 | + - "Namespace: {{ cifmw_fdp_update_edpm_containers_namespace | default('openstack') }}" |
| 168 | + - "==============================================" |
0 commit comments