Ansible template to setup GitLab server in Docker container

Alex KondratievAlex Kondratiev
Pavlo KonobeyevPavlo Konobeyev

5 min read

Automated setup and configuration of Nginx along with SSL certificates from Let’s Encrypt. Ansible template for Docker setup and configuration of GitLab.


What’s inside?

What will you get?

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

Requirements:

  • Before you will start working with this ansible template you need to make sure that you have all of the listed things below:
    A server with Ubuntu 20.04 installed. 2Gb RAM is recommended minimum for GitLab.
  • Ansible 2.9 is 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:

shell

1wget -qO- https://get.docker.com/ | sh
2sudo 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:

shell

1grep port /etc/ssh/sshd_config
2port 7799
3service ssh restart
  • DNS records for GitLab and Registry:

shell

1host gitlab.thedockerexperts.com
2gitlab.thedockerexperts.com has address 138.68.101.99
3host registry.thedockerexperts.com
4registry.thedockerexperts.com has address 138.68.101.99

Step 1: Preparation for playbook launch

Before the playbook launch with the ansible role of GitLab setup, we need to prepare the variables and develop the playbook itself.

Let’s create a directory and necessary files on your local machine:

yaml

1├── deploy-gitlab.yml
2├── host_vars
3│└── gitlab.thedockerexperts.com
4├── hosts
5└── requirements.yml├── deploy-gitlab.yml
6├── host_vars
7│└── gitlab.thedockerexperts.com
8├── hosts
9└── requirements.yml

Playbook:

yaml

1---
2hosts: all
3roles: ansible-docker-gitlab

Config file:

yaml

1gitlab_ssh_host: gitlab.thedockerexperts.com
2registry_host: registry.thedockerexperts.com
3gitlab_email_from: git@thedockerexperts.com
4gitlab_email_display_name: GitLab DockerExperts
5gitlab_email_reply_to: notify@thedockerexperts.com
6time_zone: EET

Host file:

yaml

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

Requirements requirements.yml:

yaml

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

Step 2: Execution of the playbook

To start we need to setup dependencies:

shell

1ansible-galaxy install --force -r requirements.yml
2After that we can proceed directly to the launch:
3ansible-playbook -i hosts deploy-gitlab.yml

Password change is required after that:

gitlab

We log in GitLab using credentials:

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

Moreover, if you're curious about how to use Docker you can refer to our guide about top docker commands. It will help you gain confidence in using all the docker commands.

Use this article as a how-to guide to practice regularly and docker commands will become second nature to you.

Alex Kondratiev

Alex Kondratiev

Founder of ITsyndicate. DevOps Enthusiast with 15+ years of experience in cloud, Infrastructure as Code, Kubernetes, and automation. Specialized in architecting secure, scalable, and resilient systems.

Plan the present.
Build the future.