Skip to content

Commit ca568a7

Browse files
committed
Add 'gitlab' role
- GitLab is an open source GitHub clone - http://gitlab.org/; - 'gitlab' role installs and configures GitLab CE with nginx as webserver and MySQL as backend database. Support for PostgreSQL database will be added at a later date; - 'gitlab' role is idempotent and should support future upgrades of GitLab CE (new releases every 22nd of the month); - currently 'gitlab' role does not support all GitLab configuration options, support will be added as needed over time;
1 parent 0a84185 commit ca568a7

File tree

27 files changed

+1209
-0
lines changed

27 files changed

+1209
-0
lines changed

playbooks/gitlab.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
3+
- name: GitLab support
4+
hosts: ginas_gitlab
5+
sudo: yes
6+
7+
roles:
8+
- { role: gitlab, tags: gitlab }
9+
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
# role: gitlab (Open Source GitHub clone)
3+
# Homepage: http://gitlabhq.com/
4+
5+
6+
# ---- Basic options ----
7+
8+
# Should GitLab role manage it's own dependencies (database, web server)?
9+
gitlab_dependencies: True
10+
11+
# What version of GitLab to install / manage
12+
gitlab_version: '6.6'
13+
14+
# Allow automatic upgrades to next version? If not, Ansible will stop execution
15+
# when it detects that GitLab requires upgrade
16+
gitlab_auto_upgrade: True
17+
18+
19+
# ---- GitLab instance configuration ----
20+
21+
# What database to use for GitLab instnce? Choices: mysql, postgresql
22+
# Currently only MySQl is supported
23+
gitlab_database: 'mysql'
24+
25+
# Domain which will be used for nginx server and gitlab-shell access
26+
# GitLab will be configured with HTTPS enabled by default
27+
gitlab_domain: 'code.{{ ansible_domain }}'
28+
29+
# E-mail sender name used by GitLab
30+
gitlab_email_name: 'GitLab'
31+
32+
# E-mail address used by GitLab
33+
gitlab_email_from: 'git@{{ gitlab_domain }}'
34+
35+
# E-mail address for GitLab support
36+
gitlab_email_support: 'root@{{ ansible_domain }}'
37+
38+
39+
# ---- New user configuration ----
40+
41+
# Enable sign up on the front page?
42+
gitlab_signup_enabled: 'true'
43+
44+
# Default project limit for new users
45+
gitlab_default_projects_limit: '50'
46+
47+
# Should new users be able to create groups?
48+
gitlab_default_can_create_group: 'true'
49+
50+
# Can users change their own username?
51+
gitlab_username_changing_enabled: 'false'
52+
53+
# Default GitLab theme to use
54+
gitlab_default_theme: '2'
55+
56+
57+
# ---- Internal application settings ----
58+
59+
# nginx client_max_body_size value
60+
gitlab_nginx_client_max_body_size: '5m'
61+
62+
# nginx - gitlab proxy timeout in seconds
63+
gitlab_nginx_proxy_timeout: '300'
64+
65+
# Max git upload size in bytes
66+
gitlab_git_max_size: '5242880'
67+
68+
# git connection timeout in seconds
69+
gitlab_git_timeout: '10'
70+
71+
# unicorn connection timeout in seconds
72+
gitlab_unicorn_timeout: '30'
73+
74+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
3+
- name: Restart gitlab
4+
service: name=gitlab state=restarted
5+
when: gitlab_status_ce_installed is defined and gitlab_status_ce_installed
6+

playbooks/roles/gitlab/meta/main.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
3+
dependencies:
4+
5+
- role: mysql
6+
when: (gitlab_dependencies is defined and gitlab_dependencies) and
7+
(gitlab_database is defined and gitlab_database and gitlab_database == 'mysql')
8+
9+
mysql_databases:
10+
- name: '{{ gitlab_database_config[gitlab_database].database }}'
11+
state: 'present'
12+
13+
mysql_users:
14+
- name: '{{ gitlab_database_config[gitlab_database].username }}'
15+
host: '{{ gitlab_database_config[gitlab_database].hostname }}'
16+
priv: '{{ gitlab_database_config[gitlab_database].database }}.*:ALL'
17+
state: 'present'
18+
19+
- role: nginx
20+
nginx_servers: [ '{{ gitlab_nginx_server }}' ]
21+
nginx_upstreams: [ '{{ gitlab_nginx_upstream }}' ]
22+
when: (gitlab_dependencies is defined and gitlab_dependencies)
23+
24+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
3+
- name: Check if gitlab-shell is installed
4+
set_fact:
5+
gitlab_status_shell_installed: True
6+
when: (ansible_local.gitlab_shell is defined and ansible_local.gitlab_shell.instance)
7+
8+
- name: Check if gitlab-shell has to be upgraded
9+
set_fact:
10+
gitlab_status_shell_upgrade: True
11+
when: (gitlab_status_shell_installed is defined and gitlab_status_shell_installed) and
12+
(ansible_local.gitlab_shell.instance.gitlab_version != gitlab_version) and
13+
(ansible_local.gitlab_shell.instance.shell_version != gitlab_version_map[gitlab_version].shell)
14+
15+
- name: Fail if auto upgrade is disabled
16+
fail: msg="gitlab-shell requires an upgrade but automatic upgrades are disabled"
17+
when: (gitlab_status_shell_upgrade is defined and gitlab_status_shell_upgrade) and
18+
(gitlab_auto_upgrade is undefined or (gitlab_auto_upgrade is defined and not gitlab_auto_ugrade))
19+
20+
- name: Check if GitLab CE is installed
21+
set_fact:
22+
gitlab_status_ce_installed: True
23+
when: (ansible_local.gitlab_ce is defined and ansible_local.gitlab_ce.instance)
24+
25+
- name: Check if GitLab CE has to be upgraded
26+
set_fact:
27+
gitlab_status_ce_upgrade: True
28+
when: (gitlab_status_ce_installed is defined and gitlab_status_ce_installed) and
29+
(ansible_local.gitlab_ce.instance.gitlab_version != gitlab_version) and
30+
(ansible_local.gitlab_ce.instance.ce_version != gitlab_version_map[gitlab_version].ce)
31+
32+
- name: Fail if auto upgrade is disabled
33+
fail: msg="GitLab CE requires an upgrade but automatic upgrades are disabled"
34+
when: (gitlab_status_ce_upgrade is defined and gitlab_status_ce_upgrade) and
35+
(gitlab_auto_upgrade is undefined or (gitlab_auto_upgrade is defined and not gitlab_auto_upgrade))
36+
37+
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
3+
# ---- git clone & git checkout ----
4+
5+
- name: Clone gitlab-shell source code
6+
git: repo={{ gitlab_source_address + gitlab_source_repository.shell }}
7+
dest={{ gitlab_sources + '/' + gitlab_source_repository.shell }}
8+
version={{ gitlab_version_map[gitlab_version].shell }}
9+
bare=yes update=yes
10+
sudo_user: '{{ gitlab_user }}'
11+
register: gitlab_register_shell_source
12+
13+
- name: Check if gitlab-shell is checked out
14+
stat: path={{ gitlab_home }}/gitlab-shell
15+
register: gitlab_register_shell_directory
16+
17+
- name: Create gitlab-shell directory
18+
file: path={{ gitlab_home }}/gitlab-shell state=directory
19+
owner={{ gitlab_user }} group={{ gitlab_group }} mode=0755
20+
when: (gitlab_register_shell_source is defined and gitlab_register_shell_source.changed == True) or
21+
(gitlab_register_shell_directory is defined and gitlab_register_shell_directory.stat.exists == False)
22+
23+
- name: Prepare gitlab-shell worktree
24+
template: src=srv/users/git/gitlab-shell/git.j2 dest={{ gitlab_home }}/gitlab-shell/.git
25+
owner={{ gitlab_user }} group={{ gitlab_group }} mode=0644
26+
when: (gitlab_register_shell_source is defined and gitlab_register_shell_source.changed == True) or
27+
(gitlab_register_shell_directory is defined and gitlab_register_shell_directory.stat.exists == False)
28+
29+
- name: Checkout gitlab-shell
30+
shell: GIT_WORK_TREE={{ gitlab_home }}/gitlab-shell git checkout -f {{ gitlab_version_map[gitlab_version].shell }}
31+
chdir={{ gitlab_sources + '/' + gitlab_source_repository.shell }}
32+
sudo_user: '{{ gitlab_user }}'
33+
register: gitlab_register_shell_checkout
34+
when: (gitlab_register_shell_source is defined and gitlab_register_shell_source.changed == True) or
35+
(gitlab_register_shell_directory is defined and gitlab_register_shell_directory.stat.exists == False)
36+
37+
38+
# ---- gitlab-shell/config.yml ----
39+
40+
- name: Check gitlab-shell configuration for changes
41+
shell: sha1sum {{ gitlab_home }}/gitlab-shell/config.yml.example | cut -d" " -f1
42+
register: gitlab_register_shell_config_checksum
43+
when: gitlab_register_shell_checkout is defined and gitlab_register_shell_checkout.changed == True
44+
45+
- name: Fail if gitlab-shell configuration changed
46+
fail: msg="gitlab-shell configuration changed, check it and update checksum"
47+
when: (gitlab_register_shell_checkout is defined and gitlab_register_shell_checkout.changed == True) and
48+
(gitlab_register_shell_config_checksum.stdout != gitlab_checksums.shell[gitlab_version_map[gitlab_version].shell].config)
49+
50+
- name: Configure gitlab-shell
51+
template: src=srv/users/git/gitlab-shell/{{ gitlab_config_map[gitlab_version].shell }}/config.yml.j2
52+
dest={{ gitlab_home }}/gitlab-shell/config.yml
53+
owner={{ gitlab_user }} group={{ gitlab_group }} mode=0644
54+
when: gitlab_register_shell_checkout is defined and gitlab_register_shell_checkout.changed == True
55+
56+
57+
# ---- Setup ----
58+
59+
- name: Setup gitlab-shell
60+
shell: ./bin/install chdir={{ gitlab_home }}/gitlab-shell
61+
sudo_user: '{{ gitlab_user }}'
62+
when: gitlab_register_shell_checkout is defined and gitlab_register_shell_checkout.changed == True
63+
64+
- name: Add GitLab host to SSH known hosts
65+
shell: ssh-keyscan -t rsa,ecdsa -H {{ gitlab_domain }} > {{ gitlab_home }}/.ssh/known_hosts
66+
sudo_user: '{{ gitlab_user }}'
67+
when: gitlab_register_shell_checkout is defined and gitlab_register_shell_checkout.changed == True
68+

0 commit comments

Comments
 (0)