From dd37acbfbd5a0c8db622a9ffae7c81e96b6b036a Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Sat, 29 Aug 2015 19:30:38 +0200 Subject: Add role to setup gitolite --- roles/gitserver/tasks/as_gituser.yaml | 13 +++++++++ roles/gitserver/tasks/main.yaml | 42 +++++++++++++++++++++++++++ roles/gitserver/tasks/restore_gitolite.yaml | 44 +++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 roles/gitserver/tasks/as_gituser.yaml create mode 100644 roles/gitserver/tasks/main.yaml create mode 100644 roles/gitserver/tasks/restore_gitolite.yaml (limited to 'roles/gitserver/tasks') diff --git a/roles/gitserver/tasks/as_gituser.yaml b/roles/gitserver/tasks/as_gituser.yaml new file mode 100644 index 0000000..69157fd --- /dev/null +++ b/roles/gitserver/tasks/as_gituser.yaml @@ -0,0 +1,13 @@ +--- +- name: Put gitolite.rc + copy: + src=gitolite.rc + dest=/var/lib/gitolite/.gitolite.rc + +- name: Stat gitolite dir + stat: path=/var/lib/gitolite/.gitolite/conf + register: gitolite_dir + +- name: Initialize gitolite and restore backup + include: restore_gitolite.yaml + when: not gitolite_dir.stat.exists diff --git a/roles/gitserver/tasks/main.yaml b/roles/gitserver/tasks/main.yaml new file mode 100644 index 0000000..7d1e3d7 --- /dev/null +++ b/roles/gitserver/tasks/main.yaml @@ -0,0 +1,42 @@ +--- +- name: Install gitolite + apt: name={{ item }} + with_items: + - gitolite3 + - git-daemon-run + +- name: Create git group + group: name=git + +- name: Create git user + user: + name=git + group=git + home="/var/lib/gitolite" + +- name: Make git dir world readable + file: + name=/var/lib/gitolite + mode=0755 + +- include: as_gituser.yaml + become: yes + become_method: su + become_user: git + +- name: Copy cgitrc.repo_service + shell: sed -e 's_/var/lib/git_/var/lib/gitolite_g' /var/lib/gitolite/.gitolite/conf/cgitrc.repo_service > /etc/cgitrc.repo_service + args: + creates: /etc/cgitrc.repo_service + +- name: Ensure correct permissions on cgitrc.repo_service + file: + name=/etc/cgitrc.repo_service + mode=0644 + +- name: Configure git-daemon + lineinfile: + dest=/etc/service/git-daemon/run + regexp="--base-path=/var/lib /var/lib/git" + line="--base-path=/var/lib/gitolite/repositories /var/lib/gitolite/repositories" + notify: Restart git-daemon diff --git a/roles/gitserver/tasks/restore_gitolite.yaml b/roles/gitserver/tasks/restore_gitolite.yaml new file mode 100644 index 0000000..c937ad1 --- /dev/null +++ b/roles/gitserver/tasks/restore_gitolite.yaml @@ -0,0 +1,44 @@ +- name: Create dummy key + shell: ssh-keygen -t rsa -b 2048 -N '' -f dummy_key + args: + chdir: /var/lib/gitolite + creates: /var/lib/gitolite/dummy_key + +- name: Initialize gitolite + shell: gitolite setup -pk dummy_key.pub + args: + chdir: /var/lib/gitolite + creates: /var/lib/gitolite/.gitolite/conf + +- name: Get repository backup + get_url: + url=https://oberon.sublab.org/protected/repositories.tar.gz + url_username="{{download_user}}" + url_password="{{download_pass}}" + validate_certs=no + dest=/var/lib/gitolite/repositories.tar.gz + +- name: Create directory for backup unpack + file: name=/var/lib/gitolite/old-repositories state=directory + +- name: Unpack repository backup + shell: tar -x --strip-components=1 -f ../repositories.tar.gz + args: + chdir: /var/lib/gitolite/old-repositories + creates: /var/lib/gitolite/old-repositories/gitolite-admin.git + +- name: Push gitolite backup + shell: gitolite push -f /var/lib/gitolite/repositories/gitolite-admin.git master:master + args: + chdir: /var/lib/gitolite/old-repositories/gitolite-admin.git + +- name: Put restore script + copy: + dest=/var/lib/gitolite/restore-backup.sh + src=restore-backup.sh + mode=0755 + +- name: Run restore + shell: ./restore-backup.sh + args: + chdir: /var/lib/gitolite -- cgit v1.2.1