August 31, 2017

Automated GitLab server setup in Docker container using Ansible playbook

What’s inside?

Automated setup and configuration of Nginx along with SSL certificates from Let’sEnrcrypt.



Automated setup and configuration of GitLab in Docker. What will you get?

Fully working system that’s being setted up within 2-3 minutes.

Requirements:

Before the start you need to make sure that you have all of the listed things below:

A server with Ubuntu 16.04 Xenial installed. 2Gb RAM is recommended minimum for GitLab.

Ansible 2.3 installed on your local machine.

Public ssh key to connect to the server.

Installed and configured Docker. Below you can see a simple command for Docker service setup:

wget -qO- https://get.docker.com/ | sh sudo usermod -aG docker $(whoami)

Python-minimal installed on the target server. Command to setup:

apt install python-minimal

Custom SSH port on the server, as port 22 will be exposed outside. Command to configure:

grep port /etc/ssh/sshd_config port 7799 service ssh restart

DNS records for GitLab and Registry:

host gitlab.thedockerexperts.com gitlab.thedockerexperts.com has address 138.68.101.99 host registry.thedockerexperts.com registry.thedockerexperts.com has address 138.68.101.99

Step 1: Preparation to playbook launch





Before the playbook launch with the role of GitLab setup, we need to prepare the variables and develop the playbook itself. Let’s create directory and necessary files on your local machine:

├── deploy-gitlab.yml ├── host_vars │ └── gitlab.thedockerexperts.com ├── hosts └── requirements.yml

Playbook:

--- hosts: all roles: ansible-docker-gitlab

Config file:

Host file:

[all] gitlab.thedockerexperts.com ansible_ssh_host=138.68.101.99 ansible_ssh_port=7799 ansible_ssh_user=root ansible_become=yes

Requirements requirements.yml :

src: git+https://gitlab.itsyndicate.org/public-area/ansible-docker-gitlab.git path: roles

Step 2: Execution of the playbook





To start we need to setup dependencies:

ansible-galaxy install --force -r requirements.yml

After that we can proceed directly to the launch:

ansible-playbook -i hosts deploy-gitlab.yml

Password change is required after that:







We login in GitLab using credentials:

user : root password: the one you’ve set up before.

WOOHOO! You’re in!



