mirror of https://github.com/ansible/ansible.git
Add role for setting up git protocol to make it easier to replace external test dependencies
parent
8ad68f12ee
commit
f485d0d3bc
@ -0,0 +1,7 @@
|
||||
repo_path: '{{ remote_tmp_dir }}/git_repositories'
|
||||
|
||||
git_package: git
|
||||
git_daemon: git-daemon
|
||||
|
||||
repositories: []
|
||||
exec: []
|
@ -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,21 @@
|
||||
- block:
|
||||
- name: "Cloning {{ repository }}"
|
||||
command: 'git clone git://localhost/{{ repository }} {{ remote_tmp_dir }}/{{ repository }}'
|
||||
when: '( exec | length ) > 0'
|
||||
register: cloned_repo
|
||||
|
||||
- name: "Running commands in {{ repository }}"
|
||||
shell: "{{ cmd }}"
|
||||
args:
|
||||
chdir: "{{ remote_tmp_dir }}/{{ repository }}"
|
||||
loop_control:
|
||||
loop_var: cmd
|
||||
loop: "{{ exec }}"
|
||||
register: update
|
||||
|
||||
always:
|
||||
- name: "Removing {{ repository }}"
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/{{ repository }}"
|
||||
state: absent
|
||||
when: cloned_repo is not skipped
|
@ -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: exec_in_clone.yml
|
||||
loop_control:
|
||||
loop_var: repository
|
||||
loop: "{{ repositories }}"
|
||||
when: "( exec | 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 @@
|
||||
git_daemon: git-daemon-run
|
Loading…
Reference in New Issue