Add role for setting up git protocol to make it easier to replace external test dependencies

pull/74103/head
s-hertel 3 weeks ago
parent 8ad68f12ee
commit 00f7196391

@ -0,0 +1,8 @@
default_git_branch: main
repo_path: '{{ remote_tmp_dir }}/git_repositories'
git_package: git
git_daemon: git-daemon
repositories: []
shell_commands: []

@ -0,0 +1,14 @@
- name: Check is repo needs to be created
stat:
path: '{{ repo_path }}/{{ repository }}'
register: stat_repo
- name: Initialize bare git repo
shell: 'git init --bare --shared {{ repo_path }}/{{ repository }}'
when: not stat_repo.stat.exists
- name: Add repo as safe
shell: 'git config --add safe.directory .'
args:
chdir: "{{ repo_path }}/{{ repository }}"
when: not stat_repo.stat.exists

@ -0,0 +1,17 @@
- include_tasks:
file: setup.yml
when: started_daemon is undefined
- include_tasks:
file: add_repository.yml
when: "( [repo_path, repository] | path_join) is not is_dir"
loop: "{{ repositories }}"
loop_control:
loop_var: repository
- include_tasks:
file: update_repository.yml
loop_control:
loop_var: repository
loop: "{{ repositories }}"
when: "( shell_commands | length ) > 0"

@ -0,0 +1,35 @@
- include_vars:
file: "{{ ansible_facts['os_family'] }}.yml"
ignore_errors: yes
- name: Create repo path
file:
state: "{{ item }}"
path: "{{ repo_path }}"
loop:
- absent
- directory
- command: "{{ git_package }} --help"
register: found_git
ignore_errors: yes
- command: "{{ git_package }} daemon --help"
register: found_daemon
ignore_errors: yes
- name: install git
package:
name:
- "{{ git_package }}"
- "{{ git_daemon }}"
state: present
update_cache: yes
when: (found_git is failed or found_daemon is failed) and ansible_facts['os_family'] in ['RedHat', 'Debian', 'FreeBSD', 'Suse']
- name: install git (apk)
shell: "apk update && apk add {{ git_package }} {{ git_daemon }} -v -v"
when: (found_git is failed or found_daemon is failed) and ansible_facts['os_family'] == 'Alpine'
- name: start git daemon
shell: "git daemon --reuseaddr --export-all --enable=receive-pack --base-path={{ repo_path }} {{ repo_path }}&"
register: started_daemon

@ -0,0 +1,23 @@
- block:
- name: "Cloning {{ repository }}"
shell: 'git clone git://localhost/{{ repository }} {{ repository }}'
args:
chdir: '{{ remote_tmp_dir }}'
when: '( shell_commands | length ) > 0'
register: cloned_repo
- name: "Running commands in {{ repository }}"
shell: "{{ cmd }}"
args:
chdir: "{{ remote_tmp_dir }}/{{ repository }}"
loop_control:
loop_var: cmd
loop: "{{ shell_commands }}"
register: update
always:
- name: "Removing {{ repository }}"
file:
path: "{{ remote_tmp_dir }}/{{ repository }}"
state: absent
when: cloned_repo is not skipped
Loading…
Cancel
Save