Deploy Self-Hosted Enterprise GitLab on Ubuntu with Ansible
Automate the deployment, TLS configuration, and day-2 tuning of a self-hosted GitLab instance on Ubuntu servers using idempotent Ansible playbooks.
Mohan Kumar BN
Senior Platform Engineer & CNCF Certified Kubestronaut
Self-Hosted GitLab for Enterprise Source Control & CI/CD
Many enterprise platform teams require an on-premises, air-gapped or VPC-isolated GitLab instance to host sensitive infrastructure repositories, Terraform modules, and GitOps manifests. Using Ansible, we automate the complete installation and reconfiguration of GitLab Omnibus on Ubuntu.
Automated Workflow
1. Prerequisite Packages & Repository Setup
- name: Install GitLab system dependencies
ansible.builtin.apt:
name:
- curl
- openssh-server
- ca-certificates
- tzdata
- perl
state: present
update_cache: true
- name: Add Official GitLab Package Repository
ansible.builtin.shell: |
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | bash
args:
creates: /etc/apt/sources.list.d/gitlab_gitlab-ce.list
2. Declarative gitlab.rb Configuration & Reconfigure
- name: Install GitLab CE with External URL
ansible.builtin.apt:
name: gitlab-ce
state: present
environment:
EXTERNAL_URL: 'https://gitlab.mkbn.local'
- name: Reconfigure GitLab Omnibus Services
ansible.builtin.command: gitlab-ctl reconfigure
After the playbook finishes, retrieve the initial root password from /etc/gitlab/initial_root_password, rotate credentials into HashiCorp Vault, and register Kubernetes-backed GitLab Runners.
Related Engineering Blueprints
Running Cloud-Native Jenkins on Kubernetes
Deploy a resilient Jenkins automation controller on Kubernetes with persistent volume storage, RBAC service accounts, and dynamic ephemeral build agent pods.
Install an External Ceph Distributed Storage Cluster Using Ansible
Provision a self-healing, multi-node Ceph distributed storage cluster with Ansible to deliver replicated block (RBD), shared file (CephFS), and object storage for Kubernetes.
How to Setup High-Availability Load Balancing with HAProxy & Keepalived
Configure redundant Active/Passive HAProxy load balancers with Keepalived VRRP floating Virtual IPs (VIP) on Ubuntu 24.04 to eliminate single points of failure.