How to Set Up a Git Server for Infrastructure Code on a VM

Infrastructure code becomes much easier to manage when every Ansible playbook, Terraform module, PowerCLI script and configuration file is stored in a controlled Git repository. A small virtual machine can provide a reliable central service without the cost or administration overhead of a large enterprise platform.

This approach suits home labs, consulting environments and small IT teams running VMware, Proxmox or other virtualisation platforms. A self-hosted Git service also keeps sensitive automation code inside your own environment, rather than placing it automatically in a public SaaS platform.

For Australian teams, location and connectivity are practical considerations. A Git VM hosted in Sydney or Melbourne may align with existing data centre arrangements, while an office using NBN can still experience limited upload performance during large clone or backup operations.

The design below uses Gitea on an Ubuntu Server VM, although the same principles apply to GitLab, Forgejo and a simple SSH-only bare repository. The goal is a maintainable platform with secure access, backups and a workflow that supports infrastructure automation.

Choose The Right Virtual Machine

A Git server does not require substantial compute resources for a small infrastructure team. Start with two virtual CPUs, 4 GB of RAM and 40–80 GB of thin-provisioned storage. Increase these values when storing large binaries, container images or extensive CI artefacts.

Use a supported Ubuntu LTS or Debian release and give the VM a fixed IP address or a DHCP reservation. Create a dedicated virtual machine rather than installing Git services alongside vCenter, monitoring or automation components. This separation makes patching and recovery safer.

Place the VM on storage covered by your normal backup policy. A local datastore is acceptable for a lab, but production repositories should have a second copy outside the host. Australian businesses may also need to consider where backups are stored to meet internal data residency and governance requirements.

Install Git And Gitea

After deploying the operating system, apply updates and install the basic packages:

sudo apt update && sudo apt upgrade -y
sudo apt install -y git curl sqlite3 openssh-server

Gitea can run with SQLite for a small installation, while PostgreSQL is a better choice for larger teams or higher availability requirements. Create a dedicated service account, download a supported Gitea release, and configure it to listen on an internal address.

Set the instance URL to a useful internal name such as https://git.lab.example.com. Configure SSH access on a dedicated port if port 22 is already used by the operating system. Restrict administrative access through the management VLAN or VPN rather than exposing the administration interface directly to the internet.

Create A Repository Layout

Keep infrastructure repositories focused and predictable. A practical layout might include ansible/, terraform/, powershell/, scripts/, inventories/ and docs/. Store environment-specific variables separately, and never commit passwords, private keys, API tokens or unencrypted secret files.

Use a .gitignore file for Terraform state, temporary output, IDE settings and generated files. Commit examples such as terraform.tfvars.example instead of real values. Ansible Vault, SOPS or an external secrets manager can protect credentials while preserving repeatable deployments.

A repository supporting VMware operations might include modules for clusters, datastores and networks, alongside PowerCLI tooling. Documentation can link to operational notes, including custom vCenter roles that define the minimum permissions required by automation accounts.

Compare Hosting Approaches

The right Git implementation depends on team size, authentication requirements and the amount of automation attached to each commit. A basic bare repository is efficient, while a web application provides pull requests, issue tracking and access controls.

Approach Suitable For Strengths Limitations
Bare Git over SSH Personal labs and small teams Very light and easy to back up No web interface or review workflow
Gitea or Forgejo Most self-hosted infrastructure teams Low resource use, pull requests and teams Requires application maintenance
GitLab Larger teams and integrated CI/CD Extensive features and runners Higher CPU, RAM and storage needs
Hosted Git service Distributed teams and managed operations Minimal server administration Data governance and recurring subscription costs

For a home lab in Brisbane, Gitea is often a sensible balance between capability and resource usage. A Melbourne consultancy with several engineers may prefer GitLab if code review, runners and project management are central to the workflow.

Secure Access And Authentication

Use SSH keys for Git operations and disable password-based SSH login where practical. Enforce strong passwords for the web interface, enable multi-factor authentication, and create individual accounts instead of sharing an administrator login.

A reverse proxy such as Nginx or Caddy can provide HTTPS, redirect HTTP requests and simplify certificate renewal. If the service is reachable from outside the LAN, place it behind a VPN, firewall or identity-aware access layer. Avoid exposing SSH and the web interface broadly just because the VM is small.

Set repository permissions according to responsibility. Read-only access may be sufficient for monitoring or deployment systems, while write access should be limited to trusted maintainers. Service accounts used by Ansible or CI should have narrowly scoped tokens and no interactive shell access.

Automate Validation With Git Hooks

Infrastructure code should be checked before it reaches a production branch. Run ansible-lint, yamllint, terraform fmt, terraform validate and PowerShell syntax checks as appropriate. A pre-commit configuration can provide fast feedback on an engineer’s workstation.

For shared validation, use Gitea Actions, a lightweight runner or a separate Jenkins instance. A useful pipeline might validate a Terraform plan, perform an Ansible syntax check and publish results without applying changes automatically. Approval should be required before any production deployment.

Schedule automation according to local operating practices. Teams working across Sydney, Perth and Adelaide should record timestamps in UTC and document the relevant Australian Eastern or Western time zone. This avoids confusion around daylight saving changes when a pipeline or maintenance window runs overnight.

Protect Repositories And Backups

Back up both the Git repositories and the application configuration. For Gitea, include the database, attachments, repository data, SSH keys and configuration files. A filesystem snapshot alone is not a complete backup unless it is coordinated with the database state.

Use a three-copy strategy where possible: the live VM, a backup repository and an offline or geographically separate copy. Test restoration by deploying a temporary VM and cloning a sample repository. A backup that has never been restored is an assumption rather than a recovery plan.

Keep the host and guest patched, monitor disk usage and alert on failed backup jobs. If the VM runs on a free or low-cost home lab platform, this free home lab guide can help shape a broader virtualisation setup without turning the Git service into an unmaintained appliance.

Operate The Service Responsibly

Document the VM name, IP address, DNS record, administrator process, backup schedule and recovery steps in a location accessible during an outage. Record which repositories contain production code and which credentials must be rotated after a compromise.

Review access quarterly, remove departed users promptly and rotate deploy keys when their purpose ends. Keep a maintenance log for operating system updates, Gitea upgrades and configuration changes. Check the service’s licensing and operational boundaries alongside your organisation’s policies; the site’s usage disclaimer provides a useful example of why technical resources should be accompanied by clear terms.

A small Git server can become a dependable foundation for infrastructure as code when its scope is clear, access is controlled and recovery is tested. Deploy the VM, create a pilot repository, add validation checks and verify a full restore before moving critical automation into production.