|
118 | 118 | mode: "{{ build_stream_dir_mode }}" |
119 | 119 |
|
120 | 120 | # ------------------------------------------------------------------- |
121 | | -# 4) Deploy quadlet using template + restart via handlers |
| 121 | +# 4) Pull container image |
122 | 122 | # ------------------------------------------------------------------- |
123 | | -- name: Ensure quadlet directory exists |
| 123 | +- name: Pull omnia_build_stream image from Docker Hub |
| 124 | + containers.podman.podman_image: |
| 125 | + name: "{{ build_stream_image_name }}" |
| 126 | + tag: "{{ build_stream_image_tag }}" |
| 127 | + state: present |
| 128 | + register: image_pull_result |
| 129 | + |
| 130 | +- name: Display image pull result |
| 131 | + ansible.builtin.debug: |
| 132 | + msg: "{{ build_stream_image_pull_success_msg }}" |
| 133 | + verbosity: 2 |
| 134 | + when: image_pull_result is succeeded |
| 135 | + |
| 136 | + # Generate SSL certificates |
| 137 | +- name: Check if SSL certificates already exist |
| 138 | + ansible.builtin.stat: |
| 139 | + path: "{{ build_stream_ssl_cert }}" |
| 140 | + register: ssl_cert_stat |
| 141 | + |
| 142 | +- name: Create SSL certificate directory |
124 | 143 | ansible.builtin.file: |
125 | | - path: "{{ quadlet_dir }}" |
| 144 | + path: "{{ build_stream_ssl_dir }}" |
126 | 145 | state: directory |
127 | 146 | mode: "{{ build_stream_dir_mode }}" |
| 147 | + when: not ssl_cert_stat.stat.exists |
128 | 148 |
|
129 | | -- name: Deploy build_stream quadlet file from template |
130 | | - ansible.builtin.template: |
131 | | - src: "build_stream.j2" |
132 | | - dest: "{{ build_stream_quadlet_path }}" |
133 | | - mode: "{{ build_stream_quadlet_file_mode }}" |
134 | | - notify: |
135 | | - - Reload systemd |
136 | | - - Restart build_stream |
| 149 | +- name: Generate self-signed SSL certificate |
| 150 | + ansible.builtin.command: | |
| 151 | + openssl req -x509 -newkey rsa:4096 -nodes -days {{ build_stream_ssl_days }} |
| 152 | + -keyout {{ build_stream_ssl_key }} |
| 153 | + -out {{ build_stream_ssl_cert }} |
| 154 | + -subj "/C=US/ST=State/L=City/O=Omnia/CN={{ ansible_hostname }}" |
| 155 | + -addext "subjectAltName=DNS:{{ ansible_hostname }},DNS:localhost,IP:{{ ansible_default_ipv4.address }}" |
| 156 | + when: not ssl_cert_stat.stat.exists |
| 157 | + changed_when: true |
137 | 158 |
|
138 | | -- name: Enable and start build_stream service |
139 | | - ansible.builtin.systemd_service: |
140 | | - name: "{{ build_stream_service }}" |
141 | | - enabled: true |
142 | | - state: started |
| 159 | +- name: Set permissions on SSL certificates |
| 160 | + ansible.builtin.file: |
| 161 | + path: "{{ item }}" |
| 162 | + mode: "{{ build_stream_ssl_file_mode }}" |
| 163 | + loop: |
| 164 | + - "{{ build_stream_ssl_cert }}" |
| 165 | + - "{{ build_stream_ssl_key }}" |
| 166 | +# ------------------------------------------------------------------- |
| 167 | +# 4) Deploy quadlet using template + restart via handlers |
| 168 | +# ------------------------------------------------------------------- |
| 169 | +- name: Deploy build_stream container and check deployment status |
| 170 | + block: |
| 171 | + - name: Ensure quadlet directory exists |
| 172 | + ansible.builtin.file: |
| 173 | + path: "{{ quadlet_dir }}" |
| 174 | + state: directory |
| 175 | + mode: "{{ build_stream_dir_mode }}" |
143 | 176 |
|
144 | | -# Ensure restart happens before validation |
145 | | -- name: Apply systemd reload/restart now |
146 | | - ansible.builtin.meta: flush_handlers |
| 177 | + - name: Create Quadlet service file |
| 178 | + ansible.builtin.template: |
| 179 | + src: build_stream.j2 |
| 180 | + dest: "{{ build_stream_quadlet_path }}" |
| 181 | + mode: "{{ build_stream_quadlet_file_mode }}" |
| 182 | + register: quadlet_out |
| 183 | + notify: |
| 184 | + - Reload systemd |
147 | 185 |
|
148 | | -- name: Wait until omnia_build_stream container exists and is running |
149 | | - containers.podman.podman_container_info: |
150 | | - name: "{{ build_stream_container_name }}" |
151 | | - register: bs_info |
152 | | - retries: "{{ bs_container_wait_retries }}" |
153 | | - delay: "{{ bs_container_wait_delay }}" |
154 | | - until: |
155 | | - - bs_info.containers is defined |
156 | | - - bs_info.containers | length > 0 |
157 | | - - bs_info.containers[0].State is defined |
158 | | - - bs_info.containers[0].State.Running | bool |
| 186 | + - name: Deploy build_stream quadlet file from template |
| 187 | + ansible.builtin.template: |
| 188 | + src: "build_stream.j2" |
| 189 | + dest: "{{ build_stream_quadlet_path }}" |
| 190 | + mode: "{{ build_stream_quadlet_file_mode }}" |
| 191 | + notify: |
| 192 | + - Reload systemd |
| 193 | + - Restart build_stream |
159 | 194 |
|
160 | | -# ------------------------------------------------------------------- |
161 | | -# 5) Validate HTTPS connectivity from inside build_stream |
162 | | -# ------------------------------------------------------------------- |
163 | | -- name: Build curl command |
164 | | - ansible.builtin.set_fact: |
165 | | - curl_cmd: |
166 | | - - curl |
167 | | - - -sS |
168 | | - - -o |
169 | | - - /dev/null |
170 | | - - -w |
171 | | - - "%{http_code}\n" |
172 | | - - --cacert |
173 | | - - "{{ build_stream_pulp_cert_container_path }}" |
174 | | - - "{{ pulp_base_url }}/pulp/api/v3/status/" |
175 | | - changed_when: false |
| 195 | + - name: Enable and start build_stream service |
| 196 | + ansible.builtin.systemd_service: |
| 197 | + name: "{{ build_stream_service }}" |
| 198 | + enabled: true |
| 199 | + state: started |
176 | 200 |
|
177 | | -- name: Test HTTPS from build_stream to Pulp (exec) |
178 | | - containers.podman.podman_container_exec: |
179 | | - name: "{{ build_stream_container_name }}" |
180 | | - argv: "{{ curl_cmd }}" |
181 | | - register: curl_status |
182 | | - changed_when: false |
183 | | - failed_when: false |
| 201 | + # Ensure restart happens before validation |
| 202 | + - name: Apply systemd reload/restart now |
| 203 | + ansible.builtin.meta: flush_handlers |
| 204 | + |
| 205 | + - name: Wait until omnia_build_stream container exists and is running |
| 206 | + containers.podman.podman_container_info: |
| 207 | + name: "{{ build_stream_container_name }}" |
| 208 | + register: bs_info |
| 209 | + retries: "{{ bs_container_wait_retries }}" |
| 210 | + delay: "{{ bs_container_wait_delay }}" |
| 211 | + until: |
| 212 | + - bs_info.containers is defined |
| 213 | + - bs_info.containers | length > 0 |
| 214 | + - bs_info.containers[0].State is defined |
| 215 | + - bs_info.containers[0].State.Running | bool |
184 | 216 |
|
185 | | -- name: Fail if HTTPS test is not 200 |
186 | | - ansible.builtin.fail: |
187 | | - msg: "{{ build_stream_https_failure_msg }}" |
188 | | - when: (curl_status.stdout | trim) != "200" |
| 217 | + # ------------------------------------------------------------------- |
| 218 | + # 5) Validate HTTPS connectivity from inside build_stream |
| 219 | + # ------------------------------------------------------------------- |
| 220 | + - name: Build curl command |
| 221 | + ansible.builtin.set_fact: |
| 222 | + curl_cmd: |
| 223 | + - curl |
| 224 | + - -sS |
| 225 | + - -o |
| 226 | + - /dev/null |
| 227 | + - -w |
| 228 | + - "%{http_code}\n" |
| 229 | + - --cacert |
| 230 | + - "{{ build_stream_pulp_cert_container_path }}" |
| 231 | + - "{{ pulp_base_url }}/pulp/api/v3/status/" |
| 232 | + changed_when: false |
189 | 233 |
|
190 | | -# ------------------------------------------------------------------- |
| 234 | + - name: Test HTTPS from build_stream to Pulp |
| 235 | + containers.podman.podman_container_exec: |
| 236 | + name: "{{ build_stream_container_name }}" |
| 237 | + argv: "{{ curl_cmd }}" |
| 238 | + register: curl_status |
| 239 | + changed_when: false |
| 240 | + failed_when: false |
| 241 | + |
| 242 | + - name: Fail if HTTPS test is not 200 |
| 243 | + ansible.builtin.fail: |
| 244 | + msg: "{{ build_stream_https_failure_msg }}" |
| 245 | + when: (curl_status.stdout | trim) != "200" |
| 246 | +# -------------------------------------------------------------------- |
191 | 247 | # 6) Validate health API endpoint https://localhost:{{ build_stream_port }}/health" |
192 | 248 | # ------------------------------------------------------------------- |
193 | | -- name: Wait until omnia_build_stream container exists and is running |
194 | | - containers.podman.podman_container_info: |
195 | | - name: "{{ build_stream_container_name }}" |
196 | | - register: bs_info |
197 | | - retries: "{{ bs_container_wait_retries }}" |
198 | | - delay: "{{ bs_container_wait_delay }}" |
199 | | - until: |
200 | | - - bs_info.containers is defined |
201 | | - - bs_info.containers | length > 0 |
202 | | - - bs_info.containers[0].State is defined |
203 | | - - bs_info.containers[0].State.Running | bool |
| 249 | + - name: Wait until omnia_build_stream container exists and is running |
| 250 | + containers.podman.podman_container_info: |
| 251 | + name: "{{ build_stream_container_name }}" |
| 252 | + register: bs_info |
| 253 | + retries: "{{ bs_container_wait_retries }}" |
| 254 | + delay: "{{ bs_container_wait_delay }}" |
| 255 | + until: |
| 256 | + - bs_info.containers is defined |
| 257 | + - bs_info.containers | length > 0 |
| 258 | + - bs_info.containers[0].State is defined |
| 259 | + - bs_info.containers[0].State.Running | bool |
| 260 | + |
| 261 | + rescue: |
| 262 | + - name: Build_stream container deployment failed |
| 263 | + ansible.builtin.fail: |
| 264 | + msg: "{{ build_stream_container_failure_msg }}" |
0 commit comments