This repository provides an Ansible-based solution to set up the following services across three separate servers:
- GitLab: Self-hosted Git repository management (Server 1)
- GitLab Runner: For CI/CD jobs (Server 2)
- PostgreSQL: Dedicated database server (Server 3)
Update the inventory.ini file with your servers’ addresses:
[gitlab]
gitlab.example.com ansible_host=192.168.10.11
[gitlab_runner]
runner.example.com ansible_host=192.168.10.12
[postgresql]
db.example.com ansible_host=192.168.10.13- Each service is installed and configured only on its designated host.
- All tasks are organized in Ansible roles for better maintainability.
- The project uses a single playbook,
playbook.yml, to orchestrate the installation.
-
Clone the repository
git clone https://github.com/parvvareshInfrastructure/Ansible-lab cd ansible-lab -
Edit the inventory
- Open
inventory.iniand set your server hostnames or IP addresses.
- Open
-
(Optional) Adjust variables
- If you want to set custom values (e.g., database passwords, external URLs), edit the role defaults or provide extra variables.
-
Run the playbook
ansible-playbook -i inventory.ini playbook.yml
- Make sure you have SSH access and
become(sudo) privileges on all target servers.
- Make sure you have SSH access and
- Installs GitLab CE
- Configures and starts the GitLab service
- Installs GitLab Runner
- Ensures the Runner service is enabled and running
- Optionally registers the runner if registration token and GitLab URL are provided
- Installs PostgreSQL server
- Starts and enables the PostgreSQL service
- Creates a user and a database for GitLab (you can customize these in the role)
-
Database configuration: You may need to update GitLab’s database settings (in
/etc/gitlab/gitlab.rb) to point to the external PostgreSQL host. This can be done using an Ansiblelineinfileortemplatetask. -
Runner registration: If you want to automate runner registration, supply the
registration_tokenandgitlab_urlas variables. Otherwise, register manually using the output from your GitLab instance.
- Ansible 2.9+
- Target servers running Ubuntu (roles can be adapted for other distributions)
- Sudo privileges on all target servers
- This setup is designed for test or internal deployments. For production, review each role for hardening, TLS configuration, and secure secret handling.
- Adjust firewalls and security groups as needed so services can communicate.
-
Check Ansible logs for errors during playbook execution.
-
Ensure all target servers are reachable and have Python installed.
-
After deployment, access:
- GitLab: http://gitlab.example.com
- GitLab Runner: Managed by the GitLab UI
- PostgreSQL: On
db.example.com(customize users/passwords as needed)
MIT License. Use at your own risk.