-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This role accepts a single complex data structure to clone a git repository with multiple remotes and branches. (cherry picked from commit 2fae914)
- Loading branch information
Showing
4 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
- name: "Configure repository branch" | ||
block: | ||
- name: "Create local branch" | ||
ansible.builtin.command: | ||
cmd: "git branch -f {{ branch }} {{ remote.name }}/{{ branch }}" | ||
chdir: "{{ git_repo_repository.dir }}/{{ git_repo_repository.name }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
- name: "Clone repository" | ||
ansible.builtin.git: | ||
repo: "{{ remote.url }}" | ||
remote: "{{ remote.name }}" | ||
version: "{{ (remote.branches[0]) if (remote.branches is defined) else 'HEAD' }}" | ||
dest: "{{ git_repo_repository.dir }}/{{ git_repo_repository.name }}" | ||
accept_newhostkey: yes | ||
|
||
- name: "Configure additional branches for initial remote" | ||
ansible.builtin.include_tasks: branch.yml | ||
when: (remote.branches is defined) and (remote.branches | length > 1) | ||
loop: "{{ remote.branches[1:] }}" | ||
loop_control: | ||
loop_var: branch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
- name: "Configure git repository" | ||
ansible.builtin.include_tasks: "{{ 'clone.yml' if ansible_loop.first else 'remote.yml' }}" | ||
loop: "{{ git_repo_repository.remotes }}" | ||
loop_control: | ||
loop_var: remote | ||
extended: yes | ||
label: "{{ remote.name }}" | ||
|
||
- name: "Local bundle config" | ||
when: git_repo_repository.install_gems is defined and git_repo_repository.install_gems | ||
block: | ||
- name: "Create .bundle/gems" | ||
ansible.builtin.file: | ||
path: "{{ git_repo_repository.dir }}/{{ git_repo_repository.name }}/.bundle/gems" | ||
state: directory | ||
- name: "Configure bundler to use .bundle/gems" | ||
ansible.builtin.command: | ||
cmd: "bundle config --local path .bundle/gems" | ||
chdir: "{{ git_repo_repository.dir }}/{{ git_repo_repository.name }}" | ||
- name: "Install Gems" | ||
community.general.bundler: | ||
state: present | ||
chdir: "{{ git_repo_repository.dir }}/{{ git_repo_repository.name }}" | ||
|
||
- name: "Create venv and install python packages" | ||
ansible.builtin.pip: | ||
name: "{{ git_repo_repository.python_packages }}" | ||
virtualenv: "{{ git_repo_repository.dir }}/{{ git_repo_repository.name }}/env" | ||
virtualenv_command: "python3 -m venv" | ||
virtualenv_site_packages: yes | ||
when: (git_repo_repository.python_packages is defined) and (git_repo_repository.python_packages | length >= 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
- name: "Configure additional remote for repository" | ||
block: | ||
- name: "Configure remote url" | ||
community.general.git_config: | ||
scope: local | ||
repo: "{{ git_repo_repository.dir }}/{{ git_repo_repository.name }}" | ||
name: "remote.{{ remote.name }}.url" | ||
value: "{{ remote.url }}" | ||
- name: "Configure remote fetch" | ||
community.general.git_config: | ||
scope: local | ||
repo: "{{ git_repo_repository.dir }}/{{ git_repo_repository.name }}" | ||
name: "remote.{{ remote.name }}.fetch" | ||
value: '+refs/heads/*:refs/remotes/{{ remote.name }}/*' | ||
- name: "Fetch remote" | ||
ansible.builtin.command: | ||
cmd: "git fetch {{ remote.name }}" | ||
chdir: "{{ git_repo_repository.dir }}/{{ git_repo_repository.name }}" | ||
|
||
- name: "Configure branches for additional remote" | ||
ansible.builtin.include_tasks: branch.yml | ||
when: remote.branches is defined | ||
loop: "{{ remote.branches }}" | ||
loop_control: | ||
loop_var: branch |