--- # FIXME: Normally that part should not be needed, but... # if all "required" projects in Zuul var would not be available, # later we will have an error: # # TASK [repo_setup : Make sure git-core package is installed] ******************** # fatal: [hypervisor -> controller-0(controller-0.hypervisor)]: FAILED! => # fact that ''no_log: true'' was specified # # OR # # TASK [repo_setup : Make sure git-core package is installed] ******************** # ok: [hypervisor -> controller-0(controller-0.hypervisor)] # TASK [repo_setup : Get repo-setup repository] ********************************** # fatal: [hypervisor -> controller-0(controller-0.hypervisor)]: FAILED! => # fact that ''no_log: true'' was specified # - name: Sync zuul content if available when: - (zuul is defined) or (zuul_vars.zuul is defined) - (zuul is defined) or (zuul_vars.zuul.items is defined) - (zuul is defined) or (zuul_vars.zuul.projects is defined) - not cifmw_reproducer_skip_fetch_repositories | default(false) delegate_to: controller-0 delegate_facts: true vars: _zuul: "{{ zuul_vars.zuul | default(zuul) }}" # grab the depends-on patches from the current zuul run if exists, # otherwise rely on the one from the job to reproduce _depends_on_patches: "{{ zuul['items'] | default(_zuul['items']) }}" block: - name: Check if repository directories already exist when: job_id is defined ansible.builtin.stat: path: "{{ item.project.src_dir }}" register: repos_dir_stats with_items: "{{ _depends_on_patches }}" - name: Ensure we are not in the job_id branch when: - repos_dir_stats is defined - not (item.1.skipped | default(false)) - item.1.stat.exists ansible.builtin.git: dest: "{{ item.0.project.src_dir }}" repo: "https://{{ item.0.project.canonical_name }}" version: "origin/main" force: true loop: "{{ _depends_on_patches | zip(repos_dir_stats.results) | list }}" - name: Fetch zuul.items repositories block: - name: Fetch zuul.items repositories vars: _skip_refspec: "{{ job_id is not defined or repo.change is not defined }}" ansible.builtin.git: dest: "{{ repo.project.src_dir }}" repo: "https://{{ repo.project.canonical_hostname }}/{{ repo.project.canonical_hostname | reproducer_gerrit_infix }}{{ repo.project.name }}" refspec: "{{ omit if _skip_refspec else repo | reproducer_refspec ~ ':' ~ job_id }}" version: "{{ omit if _skip_refspec else job_id }}" force: true loop: "{{ _depends_on_patches }}" loop_control: loop_var: repo label: "{{ repo.project.name }}" rescue: - name: Rebase on top of existing change if we tried to pull on the same repo twice vars: refspec: "{{ item['invocation']['module_args']['refspec'] }}" dest_dir: "{{ item['invocation']['module_args']['dest'] }}" when: - item.failed - '"Failed to download remote objects and refs:" in item.msg' - '"fatal: refusing to fetch into branch" in item.msg' - '"checked out at" in item.msg' ansible.builtin.command: # noqa: command-instead-of-module chdir: "{{ dest_dir }}" cmd: "git -c 'user.name=zuul' -c 'user.email=zuul@controller-0.com' pull --rebase origin {{ refspec | regex_replace(':.*', '') }}" loop: "{{ ansible_failed_result['results'] }}" - name: Fetch zuul.projects repositories for dependencies when: - "repo.key not in (_depends_on_patches | map(attribute='project.canonical_name'))" ansible.builtin.git: dest: "{{ repo.value.src_dir }}" repo: "https://{{ repo.value.canonical_hostname }}/{{ repo.value.canonical_hostname | reproducer_gerrit_infix }}{{ repo.value.name }}" version: "{{ repo.value.commit }}" force: true loop: "{{ _zuul['projects'] | dict2items }}" loop_control: loop_var: repo label: "{{ repo.key }}" - name: Push random code into the proper location vars: _cifmw_reproducer_all_repositories: "{{ cifmw_reproducer_repositories | default([]) }}" block: - name: Expand cifmw_reproducer_repositories to pull code from ansible controller to controller-0 when: - cifmw_reproducer_skip_fetch_repositories | default(false) - (zuul is defined) or (zuul_vars.zuul is defined) - (zuul is defined) or (zuul_vars.zuul.items is defined) - (zuul is defined) or (zuul_vars.zuul.projects is defined) # check that the project is not alredy in the user defined # cifmw_reproducer_repositories value - repo.value.name not in _user_sources vars: _zuul: "{{ zuul_vars.zuul | default(zuul) }}" _user_sources: "{{ cifmw_reproducer_repositories | default([]) | map(attribute='src') }}" _repo_entry: src: "{{ ansible_user_dir }}/{{ repo.value.src_dir | regex_replace('/$', '') }}/" dest: "{{ cifmw_reproducer_controller_user_dir }}/{{ repo.value.src_dir }}" ansible.builtin.set_fact: _cifmw_reproducer_all_repositories: "{{ _cifmw_reproducer_all_repositories + [_repo_entry] }}" loop: "{{ _zuul['projects'] | dict2items }}" loop_control: loop_var: repo label: "{{ repo.key }}" - name: Create target directories beforehand delegate_to: controller-0 vars: _destinations: >- {{ _cifmw_reproducer_all_repositories | map(attribute="dest") | map('dirname') | unique | list }} ansible.builtin.file: path: "{{ item }}" state: directory mode: "0755" loop: "{{ _destinations }}" - name: Sync local repositories to ansible controller delegate_to: localhost when: - not (cifmw_bm_sno | default(false) | bool) - item.src is abs or item.src is not match('.*:.*') ansible.posix.synchronize: src: "{{ item.src }}" dest: "{{ cifmw_reproducer_controller_user }}@controller-0:{{ item.dest }}" archive: true recursive: true delete: true loop: "{{ _cifmw_reproducer_all_repositories }}" loop_control: label: "{{ item.src | basename }}" - name: Sync remote repositories delegate_to: controller-0 delegate_facts: true when: # will match github.com:org/project, but also https://github.com/... - item.src is match('.*:.*') ansible.builtin.git: repo: "{{ item.src }}" dest: "{{ item.dest }}" version: "{{ item.version | default('HEAD') }}" refspec: "{{ item.refspec | default(omit) }}" force: true loop: "{{ _cifmw_reproducer_all_repositories }}" loop_control: label: "{{ item.src | basename }}" - name: Ensure default repositories are present ansible.builtin.include_tasks: default_repositories.yml loop: "{{ cifmw_reproducer_default_repositories }}" loop_control: loop_var: repository label: "{{ repository.src | basename }}" # installing the cifmw collection will pull it's dependencies alongside it - name: Install collections on controller-0 delegate_to: controller-0 ansible.builtin.command: chdir: "{{ _cifmw_reproducer_framework_location }}" cmd: ansible-galaxy collection install --upgrade --force .