blob: bb7038214a13be6d657308148f7317bd6162dac5 [file] [log] [blame]
Mohammed Naserdc087392024-04-01 20:26:02 -04001# Copyright (c) 2024 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: Prepare host for Molecule tests
16 hosts: all
17 tasks:
18 - name: Disable swap
vexxhost-bot200d5f72024-06-19 02:58:19 +020019 become: true
Mohammed Naserdc087392024-04-01 20:26:02 -040020 ansible.builtin.command: swapoff -a
21 ignore_errors: yes
22
vexxhost-bot200d5f72024-06-19 02:58:19 +020023 - name: Create /var/lib/etcd directory
24 become: true
25 ansible.builtin.file:
26 path: /var/lib/etcd
27 state: directory
28
29 - name: Mount ramdisk for /var/lib/etcd directory
30 become: true
31 ansible.posix.mount:
32 path: /var/lib/etcd
33 src: tmpfs
34 fstype: tmpfs
35 opts: nodev,nosuid,size=512M
36 state: mounted
37
Mohammed Naserdc087392024-04-01 20:26:02 -040038 # TODO(mnaser): Drop this when we can use https://github.com/vexxhost/atmosphere/pull/977
39 - name: Prefix all images for the job to point to mirror
40 ansible.builtin.shell: |
Mohammed Naser1bd9d0b2024-04-04 09:05:56 -040041 sed -i '/registry.atmosphere.dev/!s/ \(.*\): \(.*\)$/ \1: registry.atmosphere.dev\/\2/' roles/defaults/vars/main.yml
Mohammed Naserdc087392024-04-01 20:26:02 -040042 args:
43 chdir: "{{ zuul.project.src_dir }}"
Mohammed Naserf75ab072024-04-02 12:55:10 -040044
Mohammed Naser1bd9d0b2024-04-04 09:05:56 -040045 # NOTE(mnaser): This can be removed once the following merges
46 # https://review.opendev.org/c/zuul/zuul-jobs/+/915025
47 - name: Load "buildset_registry" fact
48 block:
49 - name: Check for results.json
50 stat:
51 path: "{{ zuul.executor.result_data_file }}"
52 register: result_json_stat
53 delegate_to: localhost
54 - name: Load information from zuul_return
55 no_log: true
56 set_fact:
57 buildset_registry: "{{ (lookup('file', zuul.executor.result_data_file) | from_json)['secret_data']['buildset_registry'] }}"
58 when:
59 - buildset_registry is not defined
60 - result_json_stat.stat.exists
61 - result_json_stat.stat.size > 0
62 - "'buildset_registry' in (lookup('file', zuul.executor.result_data_file) | from_json).get('secret_data')"
63
64 - name: Configure buildset registry
65 when: buildset_registry is defined
66 block:
67 - name: Install CA certificate for the registry
68 become: true
69 ansible.builtin.copy:
70 content: "{{ buildset_registry.cert }}"
71 dest: /usr/local/share/ca-certificates/registry.crt
72 - name: Update CA certificates
73 become: true
74 ansible.builtin.shell: update-ca-certificates
75 - name: Replace the registry in image manifest
76 ansible.builtin.replace:
77 path: "{{ zuul.project.src_dir }}/roles/defaults/vars/main.yml"
Mohammed Naserd30f18d2024-04-17 01:20:43 -040078 regexp: "{{ repo }}:"
79 replace: '{{ buildset_registry.host }}:{{ buildset_registry.port }}/{{ repo }}:'
Mohammed Naserda994232024-04-13 12:34:01 -040080 loop: "{{ zuul.artifacts | default([]) }}"
81 loop_control:
82 loop_var: zj_zuul_artifact
83 when: "'metadata' in zj_zuul_artifact and zj_zuul_artifact.metadata.type | default('') == 'container_image'"
84 vars:
85 repo: "{{ zj_zuul_artifact.metadata.repository }}"
Mohammed Naser1bd9d0b2024-04-04 09:05:56 -040086
Mohammed Naserf75ab072024-04-02 12:55:10 -040087 # TODO(mnaser): Drop this when we move to PBR
88 - name: Add current folder to Git's safe directories
89 become: true
90 ansible.builtin.shell: |
91 git config --global --add safe.directory $(pwd)
92 args:
93 chdir: "{{ zuul.project.src_dir }}"