{"id":16780891,"url":"https://github.com/jgoos/home-lab-as-code","last_synced_at":"2025-07-14T08:31:04.081Z","repository":{"id":38886958,"uuid":"497657661","full_name":"jgoos/home-lab-as-code","owner":"jgoos","description":"Generate cloud-init ready vm images via packer and deploy these via terraform.","archived":false,"fork":false,"pushed_at":"2025-05-31T21:29:07.000Z","size":93,"stargazers_count":13,"open_issues_count":9,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-01T02:33:12.639Z","etag":null,"topics":["ansible","cloud-init","homelab","homelab-automation","libvirt","packer","terraform"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jgoos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-05-29T17:15:04.000Z","updated_at":"2025-05-22T21:47:48.000Z","dependencies_parsed_at":"2025-05-17T19:21:46.229Z","dependency_job_id":"9281b74b-8246-4be6-a663-46293b97d907","html_url":"https://github.com/jgoos/home-lab-as-code","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jgoos/home-lab-as-code","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgoos%2Fhome-lab-as-code","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgoos%2Fhome-lab-as-code/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgoos%2Fhome-lab-as-code/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgoos%2Fhome-lab-as-code/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jgoos","download_url":"https://codeload.github.com/jgoos/home-lab-as-code/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgoos%2Fhome-lab-as-code/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265262588,"owners_count":23736422,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","cloud-init","homelab","homelab-automation","libvirt","packer","terraform"],"created_at":"2024-10-13T07:36:13.751Z","updated_at":"2025-07-14T08:31:04.071Z","avatar_url":"https://github.com/jgoos.png","language":"HCL","readme":"# Home Lab As Code\n\nThis repository provides a way to easily create and manage virtual machines on your local machine.\nIt uses [Packer](https://www.packer.io/) to generate `cloud-init` ready Red Hat Enterprise Linux (RHEL) images, and [Terraform](https://www.terraform.io/) to automate the provisioning of virtual machines.\nThe included dnsmasq configuration makes the virtual machines resolvable from the local machine using the `home.arpa` domain.\nAdditionally, after the provisioning process with Terraform, it will create an updated ansible inventory that can be used for further management and configuration of the provisioned machines.\n\n## Prerequisites\n\n- Have [ansible](https://www.ansible.com/) installed on your system\n- Have [packer](https://www.packer.io/) installed on your system\n- Have [terraform](https://www.terraform.io/) installed on your system\n- Red Hat Enterprise Linux (RHEL) based distribution\n\n## Downloading Content\n\n### Download ISO files\n\nTo create the RHEL images, you'll need to download the appropriate ISO files and place them in the `packer/iso-files` directory. Check the `rhel8.pkr.hcl` and `rhel9.pkr.hcl` packer config files to see which ISO files are needed.\n\n## Building Packer Images\n\nTo build the Packer images, follow these steps:\n\n``` bash\ncd packer/\u003crhel_version\u003e\npacker init .\npacker build .\n```\n\n## Configuring libvirt\n\nThe libvirt configuration is based on the following instructions:\n[howto-automated-dns-resolution-for-kvmlibvirt-guests-with-a-local-domain](https://liquidat.wordpress.com/2017/03/03/howto-automated-dns-resolution-for-kvmlibvirt-guests-with-a-local-domain/).\nThis configuration uses `home.arpa` for the domain name. (see [rfc8375](https://datatracker.ietf.org/doc/html/rfc8375)).\n\n### Edit libvirt Local Domain\n\nYou'll need to configure the default libvirt network to use the `home.arpa` domain. To check the current network configuration, run the following command:\n\n``` bash\nsudo virsh net-dumpxml default\n```\n\nExample output:\n\n``` xml\n\u003cnetwork connections='1'\u003e\n  \u003cname\u003edefault\u003c/name\u003e\n  \u003cuuid\u003e158880c3-9adb-4a44-ab51-d0bc1c18cddc\u003c/uuid\u003e\n  \u003cforward mode='nat'\u003e\n    \u003cnat\u003e\n      \u003cport start='1024' end='65535'/\u003e\n    \u003c/nat\u003e\n  \u003c/forward\u003e\n  \u003cbridge name='virbr0' stp='on' delay='0'/\u003e\n  \u003cmac address='52:54:00:fa:cb:e5'/\u003e\n  \u003cdomain name='home.arpa' localOnly='yes'/\u003e\n  \u003cip address='192.168.122.1' netmask='255.255.255.0'\u003e\n    \u003cdhcp\u003e\n      \u003crange start='192.168.122.128' end='192.168.122.254'/\u003e\n    \u003c/dhcp\u003e\n  \u003c/ip\u003e\n\u003c/network\u003e\n```\n\nMake sure the network configuration contains the following:\n\n``` xml\n\u003cdomain name='home.arpa' localOnly='yes'/\u003e\n```\n\nIf it's not, you can edit the configuration by running the following command:\n\n``` bash\nvirsh net-edit default\n```\n\n## Configuring dns masquerading\n\nTo enable DNS masquerading, you'll need to make a few changes to your system's DNS settings. First, add the following line to `/etc/NetworkManager/conf.d/localdns.conf`:\n\n``` ini\n[main]\ndns=dnsmasq\n```\n\nThen, add the following line to `/etc/NetworkManager/dnsmasq.d/libvirt_dnsmasq.conf`:\n\n``` ini\nserver=/home.arpa/192.168.122.1\n```\n\nFinally, restart the NetworkManager service:\n\n``` bash\nsudo systemctl restart NetworkManager\n```\n\n## Using Terraform to deploy VMs\n\nTo deploy the VMs using the built images, navigate to the `terraform` directory and follow these steps:\n\n### Variables\n\n1. Copy `terraform.tfvars.example` to `terraform.tfvars` (or another name that ends with .tfvars)\n2. Fill out your `terraform.tfvars` file\n3. Run `terraform init` to initialize the directory that contains a Terraform configuration\n4. Run `terraform plan -var-file=terraform.tfvars` to evaluate a Terraform configuration to determine the desired state\n5. Run `terraform apply -var-file=terraform.tfvars` to carry out the planned changes to each resource\n\n\u003e **note**: you can auto load the tfvars file without the `-var-file=terraform.tfvars` by putting `auto` in the name. For example: `terraform.auto.tfvars`\n\n## Using Ansible to provision VMs\n\nThe playbooks in the `ansible` directory can be used to provision the VMs deployed by terraform. You can use `ansible-playbook` command to run the playbooks.\nDuring the terraform deployment an `ansible.cfg` is created containing the user that is specified in the [variables.tf](terraform/variables.tf) file. The default user is `cloud-user`.\nAlso the `ansible/inventory/hosts` is updated with the new information via terraform.\n\n## Troubleshooting\n\nIn case of issues or errors, check the following:\n\n- Make sure the appropriate versions of packer and terraform are installed.\n- Check that the ISO files are in the correct directory and that the paths in the packer config files are correct.\n- Verify that the NetworkManager service is running and properly configured.\n\n## Additional Resources\n\n- [Ansible documentation](https://docs.ansible.com/)\n- [Packer documentation](https://www.packer.io/docs)\n- [Terraform documentation](https://www.terraform.io/docs/)\n- [Libvirt documentation](https://libvirt.org/docs.html)\n\nPlease note that some commands and file paths may be different depending on your operating system and specific setup.\n\n## Licensing\n\nThis repository is licensed under the MIT license. Refer to the [LICENSE](LICENSE) file for details.\n\nThis project can serve as a great starting point for automating your home lab infrastructure and can be easily customized to suit your specific needs.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjgoos%2Fhome-lab-as-code","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjgoos%2Fhome-lab-as-code","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjgoos%2Fhome-lab-as-code/lists"}