Skip to content

Ansible Role linuxfabrik.lfops.gitlab_ce

This role installs and configures GitLab CE, including regular backups.

  • After installation, the password for the first user "root" can be found in /etc/gitlab/initial_root_password.
  • One of the first steps after that would be to deactivate the registration form: In the left sidebar, select Admin > Settings > General, and expand "Sign-up restrictions". Clear the "Sign-up enabled" checkbox, then select "Save changes" (you can't disable signups without using the UI).

Available since LFOps 2.0.0.

How the Role Behaves

  • gitlab-dump.service runs with Nice=19, best-effort IO priority 7 and CPUWeight= / IOWeight= of 20 (systemd default: 100), so the dump does not slow down the application on a busy host. The weights only take effect under contention. IOWeight= only has an effect on block devices that use the BFQ IO scheduler; with none or mq-deadline, as on a RHEL 9 VM with virtio disks, it is ignored.
  • The role does not configure sshd. Git over SSH opens one connection per git fetch or git push, so CI jobs or scripts that update many repositories at once exceed the MaxStartups of the sshd role, and sshd refuses some of them. Set sshd__max_startups__group_var: '100:30:200' for GitLab hosts in the inventory, the value the GitLab documentation suggests.

Known Limitations

  • The role supports GitLab 19.2 and newer only, since gitlab.rb uses the gitlab_rails['nginx'] and registry['nginx'] settings introduced in 19.2. It aborts on a host that runs an older version, or when gitlab_ce__version names one. To restore a backup of an older version, restore it with that version by hand and upgrade along the GitLab upgrade path first.

Dependent Roles

Any LFOps playbook that installs this role runs these for you. Optional ones can be disabled via the playbook's skip variables.

Tags

gitlab_ce

  • install tar gitlab-ce
  • mkdir -p /backup/gitlab
  • Deploy /etc/systemd/system/gitlab-dump.service
  • Deploy /etc/systemd/system/gitlab-dump.timer
  • systemctl enable gitlab-dump.timer --now
  • Deploy /etc/gitlab/gitlab.rb
  • gitlab-ctl reconfigure, then wait until /-/readiness answers
  • Triggers: none.

gitlab_ce:configure

  • Same as above, but without install.
  • Triggers: none.

Mandatory Role Variables

gitlab_ce__rb_external_url

  • The URL of your GitLab instance.
  • Behind a reverse proxy that terminates TLS, use https:// and keep gitlab_ce__rb_nginx_listen_https at false. GitLab then still listens on plain HTTP, but builds its links for HTTPS and marks its session cookie Secure. With http://, the session cookie goes out without Secure.
  • Type: String.
  • Default: none

Example:

# mandatory
gitlab_ce__rb_external_url: 'https://git.example.com'

Optional Role Variables

gitlab_ce__on_calendar

  • The OnCalendar definition for the GitLab Backup. Have a look at man systemd.time(7) for the format.
  • Type: String.
  • Default: '*-*-* 23:{{ 59 | random(seed=inventory_hostname) }}'

gitlab_ce__rb_git_data_dirs_default_path

  • For setting up different data storing directory. If missing, the directory will be created by GitLab. If you want to use a single non-default directory to store git data use a path that doesn't contain symlinks. Docs
  • Type: String.
  • Default: unset

gitlab_ce__rb_gitlab_rails_backup_keep_time

  • The duration in seconds to keep backups before they are allowed to be deleted.
  • Type: Number.
  • Default: 86400

gitlab_ce__rb_gitlab_rails_backup_path

  • Backup Settings. Docs
  • Type: String.
  • Default: '/backup/gitlab'

gitlab_ce__rb_gitlab_rails_extra_matomo_site_id

  • Extra customization for Matomo.
  • Type: String.
  • Default: unset

gitlab_ce__rb_gitlab_rails_extra_matomo_url

  • Extra customization for Matomo.
  • Type: String.
  • Default: unset

gitlab_ce__rb_gitlab_rails_gitlab_default_projects_features_builds

  • Whether builds are enabled by default for projects.
  • Type: Bool.
  • Default: true

gitlab_ce__rb_gitlab_rails_gitlab_default_projects_features_container_registry

  • Whether the container registry is enabled by default for projects.
  • Type: Bool.
  • Default: true

gitlab_ce__rb_gitlab_rails_gitlab_default_projects_features_issues

  • Whether issues are enabled by default for projects.
  • Type: Bool.
  • Default: true

gitlab_ce__rb_gitlab_rails_gitlab_default_projects_features_merge_requests

  • Whether merge requests are enabled by default for projects.
  • Type: Bool.
  • Default: true

gitlab_ce__rb_gitlab_rails_gitlab_default_projects_features_snippets

  • Whether snippets are enabled by default for projects.
  • Type: Bool.
  • Default: true

gitlab_ce__rb_gitlab_rails_gitlab_default_projects_features_wiki

  • Whether the wiki feature is enabled by default for projects.
  • Type: Bool.
  • Default: true

gitlab_ce__rb_gitlab_rails_gitlab_email_display_name

  • The display name used in GitLab emails.
  • Type: String.
  • Default: 'GitLab@{{ inventory_hostname }}'

gitlab_ce__rb_gitlab_rails_gitlab_email_from

  • If your SMTP server does not like the default 'From: gitlab@gitlab.example.com', you can change the 'From' with this setting.
  • Type: String.
  • Default: '{{ mailto_root__from | d("") }}'

gitlab_ce__rb_gitlab_rails_gitlab_email_reply_to

  • The 'Reply To' address for emails if it differs from the 'From' address.
  • Type: String.
  • Default: unset

gitlab_ce__rb_gitlab_rails_ldap_enabled

  • Whether the LDAP integration is enabled. Docs
  • Type: Bool.
  • Default: false

gitlab_ce__rb_gitlab_rails_ldap_servers

  • LDAP configuration for one or more servers. Docs
  • Type: Dictionary.
  • Default: unset

gitlab_ce__rb_gitlab_rails_omniauth_allow_single_sign_on

  • OmniAuth Settings. Docs
  • Type: List.
  • Default: unset

gitlab_ce__rb_gitlab_rails_omniauth_auto_link_ldap_user

  • OmniAuth Settings. Docs
  • Type: Bool.
  • Default: unset

gitlab_ce__rb_gitlab_rails_omniauth_block_auto_created_users

  • OmniAuth Settings. Docs
  • Type: Bool.
  • Default: unset

gitlab_ce__rb_gitlab_rails_omniauth_enabled

  • OmniAuth Settings. Docs
  • Type: Bool.
  • Default: unset

gitlab_ce__rb_gitlab_rails_omniauth_external_providers

  • OmniAuth Settings. Docs
  • Type: List.
  • Default: unset

gitlab_ce__rb_gitlab_rails_omniauth_providers

  • OmniAuth Settings. Docs
  • Type: List of dictionaries.
  • Default: unset

gitlab_ce__rb_gitlab_rails_rack_attack_git_basic_auth_bantime

  • Ban an IP for x seconds after too many auth attempts.
  • Type: Number.
  • Default: 3600

gitlab_ce__rb_gitlab_rails_rack_attack_git_basic_auth_enabled

  • Whether rack attack for Git basic auth is enabled.
  • Type: Bool.
  • Default: true

gitlab_ce__rb_gitlab_rails_rack_attack_git_basic_auth_findtime

  • Reset the auth attempt counter per IP after x seconds.
  • Type: Number.
  • Default: 60

gitlab_ce__rb_gitlab_rails_rack_attack_git_basic_auth_ip_whitelist

  • List of IP addresses to whitelist from rack attack.
  • Type: List.
  • Default: ['127.0.0.1']

gitlab_ce__rb_gitlab_rails_rack_attack_git_basic_auth_maxretry

  • Limit the number of Git HTTP authentication attempts per IP.
  • Type: Number.
  • Default: 10

gitlab_ce__rb_gitlab_rails_registry_path

  • The directory in which the GitLab application expects the Container Registry images. Set it together with gitlab_ce__rb_registry_storage_filesystem_rootdirectory, which is where the registry itself stores them. Docs
  • Type: String.
  • Default: '/var/opt/gitlab/gitlab-rails/shared/registry'

gitlab_ce__rb_gitlab_rails_time_zone

  • The time zone for GitLab. Docs
  • Type: String.
  • Default: 'Europe/Zurich'

gitlab_ce__rb_gitlab_rails_uploads_directory

  • For setting up a different storage directory for uploads. If missing, the directory will be created by GitLab. Docs
  • Type: String.
  • Default: '/var/opt/gitlab/gitlab-rails/uploads'

gitlab_ce__rb_letsencrypt_enable

  • If GitLab should manage Let's Encrypt certificates itself.
  • Type: Bool.
  • Default: false

gitlab_ce__rb_nginx_listen_https

  • Set this to false only if your reverse proxy internally communicates over HTTP. Docs
  • Type: Bool.
  • Default: false

gitlab_ce__rb_nginx_listen_port

  • Override only if you use a reverse proxy. Docs
  • Type: Number.
  • Default: 80

gitlab_ce__rb_nginx_real_ip_header

  • The request header from which the bundled NGINX takes the client IP address. Apache mod_proxy and HAProxy with option forwardfor send X-Forwarded-For. Only applies if gitlab_ce__rb_nginx_real_ip_trusted_addresses is set. Docs
  • Type: String.
  • Default: 'X-Forwarded-For'

gitlab_ce__rb_nginx_real_ip_recursive

  • Whether the bundled NGINX skips all trusted addresses in gitlab_ce__rb_nginx_real_ip_header and uses the last untrusted one as the client IP address. Needed if the request passes more than one trusted proxy, and makes no difference with a single one. Only applies if gitlab_ce__rb_nginx_real_ip_trusted_addresses is set.
  • Type: Bool.
  • Default: true

gitlab_ce__rb_nginx_real_ip_trusted_addresses

  • IP addresses or CIDR ranges of the reverse proxies in front of GitLab. The bundled NGINX takes the client IP address from gitlab_ce__rb_nginx_real_ip_header only for requests from these addresses. GitLab also uses them as trusted proxies, so users do not appear signed in from the address of the proxy.
  • Type: List.
  • Default: unset

gitlab_ce__rb_nginx_ssl_certificate

  • Path to the SSL certificate.
  • Type: String.
  • Default: unset

gitlab_ce__rb_nginx_ssl_certificate_key

  • Path to the SSL certificate key.
  • Type: String.
  • Default: unset

gitlab_ce__rb_registry_database_enabled

  • Whether the Container Registry uses the metadata database instead of keeping its metadata on the storage backend. Required for online garbage collection. Docs
  • Type: Bool.
  • Default: true

gitlab_ce__rb_registry_external_url

  • The URL of the GitLab Container registry.
  • Type: String.
  • Default: unset

gitlab_ce__rb_registry_nginx_enable

  • Set this to true to enable the GitLab Container Registry.
  • Type: Bool.
  • Default: unset

gitlab_ce__rb_registry_nginx_listen_https

  • Set this to false only if your reverse proxy internally communicates over HTTP. Docs
  • Type: Bool.
  • Default: false

gitlab_ce__rb_registry_nginx_listen_port

  • The port on which the Container Registry is listening.
  • Type: Number.
  • Default: 5050

gitlab_ce__rb_registry_nginx_proxy_set_headers

  • Nginx headers for the Container Registry.
  • Type: Dictionary.
  • Default: {'X-Forwarded-Proto': 'https', 'X-Forwarded-Ssl': 'on'}

gitlab_ce__rb_registry_storage_filesystem_rootdirectory

  • The directory in which the Container Registry stores its images. Set it together with gitlab_ce__rb_gitlab_rails_registry_path, which is where the GitLab application expects them. Docs
  • Type: String.
  • Default: '/var/opt/gitlab/gitlab-rails/shared/registry'

gitlab_ce__rb_registry_storage_maintenance_readonly_enabled

  • Set this to true to put the Container Registry into read-only mode, which is required before running a manual garbage collection. Docs
  • Type: Bool.
  • Default: false

gitlab_ce__version

  • The GitLab version to install. This is useful when restoring from a backup. When unset, the latest available version is used. The role supports GitLab 19.2 and newer, and aborts on an older version.
  • Type: String.
  • Default: unset

Example (GitLab running on port 80 behind a reverse proxy, offering Google Authentication, with Matomo integration, plus running a registry):

# optional
gitlab_ce__on_calendar: '*:0/15'  # every 15 minutes

gitlab_ce__rb_git_data_dirs_default_path: '/data/gitlab/git-data'

gitlab_ce__rb_gitlab_rails_backup_keep_time: 86400
gitlab_ce__rb_gitlab_rails_backup_path: '/backup/gitlab'

gitlab_ce__rb_gitlab_rails_gitlab_email_display_name: 'My GitLab'
gitlab_ce__rb_gitlab_rails_gitlab_email_from: 'vcs@example.com'
gitlab_ce__rb_gitlab_rails_gitlab_email_reply_to: 'no-reply@example.com'

gitlab_ce__rb_gitlab_rails_gitlab_default_projects_features_builds: false
gitlab_ce__rb_gitlab_rails_gitlab_default_projects_features_container_registry: false
gitlab_ce__rb_gitlab_rails_gitlab_default_projects_features_issues: true
gitlab_ce__rb_gitlab_rails_gitlab_default_projects_features_merge_requests: true
gitlab_ce__rb_gitlab_rails_gitlab_default_projects_features_snippets: false
gitlab_ce__rb_gitlab_rails_gitlab_default_projects_features_wiki: false

gitlab_ce__rb_gitlab_rails_extra_matomo_site_id: '4711'
gitlab_ce__rb_gitlab_rails_extra_matomo_url: 'analytics.example.com/'

gitlab_ce__rb_gitlab_rails_ldap_enabled: true
gitlab_ce__rb_gitlab_rails_ldap_servers:
  main:
    label: 'LDAP'
    host: 'ldap.example.com'
    port: 636
    uid: 'sAMAccountName'
    bind_dn: 'CN=Gitlab,OU=Users,DC=example,DC=com'
    password: '<bind_user_password>'
    encryption: 'simple_tls'
    verify_certificates: true
    timeout: 10
    active_directory: false
    user_filter: '(employeeType=developer)'
    base: 'dc=example,dc=com'
    lowercase_usernames: false
    retry_empty_result_with_codes: [80]
    allow_username_or_email_login: false
    block_auto_created_users: false

gitlab_ce__rb_gitlab_rails_omniauth_allow_single_sign_on:
  - 'google_oauth2'
gitlab_ce__rb_gitlab_rails_omniauth_auto_link_ldap_user: false
gitlab_ce__rb_gitlab_rails_omniauth_block_auto_created_users: false
gitlab_ce__rb_gitlab_rails_omniauth_enabled: true
gitlab_ce__rb_gitlab_rails_omniauth_external_providers:
  - 'google_oauth2'
gitlab_ce__rb_gitlab_rails_omniauth_providers:
  - name: 'google_oauth2'
    app_id: '1095d5c3-8428-44df-89fb-cb0a77ec363f.apps.googleusercontent.com'
    app_secret: '45d85464-bc66-4236-9931-c42394f5d08e'

gitlab_ce__rb_gitlab_rails_rack_attack_git_basic_auth_bantime: 3600
gitlab_ce__rb_gitlab_rails_rack_attack_git_basic_auth_enabled: true
gitlab_ce__rb_gitlab_rails_rack_attack_git_basic_auth_findtime: 60
gitlab_ce__rb_gitlab_rails_rack_attack_git_basic_auth_ip_whitelist:
  - '127.0.0.1'
gitlab_ce__rb_gitlab_rails_rack_attack_git_basic_auth_maxretry: 10

gitlab_ce__rb_gitlab_rails_registry_path: '/srv/gitlab-registry'
gitlab_ce__rb_gitlab_rails_time_zone: 'Europe/Zurich'
gitlab_ce__rb_gitlab_rails_uploads_directory: '/srv/gitlab-uploads'

gitlab_ce__rb_letsencrypt_enable: false

gitlab_ce__rb_nginx_listen_https: false
gitlab_ce__rb_nginx_listen_port: '80'
gitlab_ce__rb_nginx_real_ip_header: 'X-Forwarded-For'
gitlab_ce__rb_nginx_real_ip_recursive: true
gitlab_ce__rb_nginx_real_ip_trusted_addresses:
  - '192.0.2.10'
gitlab_ce__rb_nginx_ssl_certificate: '/etc/pki/tls/certs/git.example.com.crt'
gitlab_ce__rb_nginx_ssl_certificate_key: '/etc/pki/tls/private/git.example.com.key'
gitlab_ce__rb_registry_database_enabled: true
gitlab_ce__rb_registry_external_url: 'https://registry.example.com'
gitlab_ce__rb_registry_nginx_enable: true
gitlab_ce__rb_registry_nginx_listen_https: false
gitlab_ce__rb_registry_nginx_listen_port: 5050
gitlab_ce__rb_registry_nginx_proxy_set_headers:
  'X-Forwarded-Proto': 'https'
  'X-Forwarded-Ssl': 'on'
gitlab_ce__rb_registry_storage_filesystem_rootdirectory: '/srv/gitlab-registry'
gitlab_ce__rb_registry_storage_maintenance_readonly_enabled: false

License

The Unlicense

Author Information

Linuxfabrik GmbH, Zurich