{"id":20543388,"url":"https://github.com/lj020326/vm-templates","last_synced_at":"2025-04-14T09:34:41.244Z","repository":{"id":44543312,"uuid":"355301862","full_name":"lj020326/vm-templates","owner":"lj020326","description":"VM build templates for multiple OS distributions","archived":false,"fork":false,"pushed_at":"2024-11-08T14:39:21.000Z","size":25916,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-11-08T15:33:48.580Z","etag":null,"topics":["centos","debian","jenkins","packer","packer-templates","redhat","ubuntu","vm-build-automation","vm-template-builds","vmware","vmware-vm-template-automation"],"latest_commit_sha":null,"homepage":"","language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lj020326.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}},"created_at":"2021-04-06T19:07:12.000Z","updated_at":"2024-11-08T14:39:27.000Z","dependencies_parsed_at":"2024-03-13T01:47:22.848Z","dependency_job_id":"70b27a29-9950-4814-9d8b-d74d0d4b6b18","html_url":"https://github.com/lj020326/vm-templates","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lj020326%2Fvm-templates","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lj020326%2Fvm-templates/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lj020326%2Fvm-templates/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lj020326%2Fvm-templates/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lj020326","download_url":"https://codeload.github.com/lj020326/vm-templates/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224866872,"owners_count":17382875,"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":["centos","debian","jenkins","packer","packer-templates","redhat","ubuntu","vm-build-automation","vm-template-builds","vmware","vmware-vm-template-automation"],"created_at":"2024-11-16T01:37:33.390Z","updated_at":"2025-04-14T09:34:41.233Z","avatar_url":"https://github.com/lj020326.png","language":"PowerShell","funding_links":[],"categories":[],"sub_categories":[],"readme":"\r\nTable of Contents:\r\n\r\n* [Information/Notes on VM Template build automation](#informationnotes-on-vm-template-build-automation)\r\n    * [1 - VM Template Build Definition Repository](#1-vm-template-build-definition-repository)\r\n      * [1.1 - VM Template Build Configurations](#1-vm-template-build-configurations)\r\n    * [2 - VM Template Build Automation from Jenkins](#2-vm-template-build-automation-from-jenkins)\r\n        * [Jenkins Project Configurations stored in YAML file format](#jenkins-project-configurations-stored-in-yaml-file-format)\r\n    * [3 - Ansible role to setup docker jenkins control node](#3-ansible-role-to-setup-docker-jenkins-control-node)\r\n        * [Setup pipeline automation library used by all jenkins jobs](#setup-pipeline-automation-library-used-by-all-jenkins-jobs)\r\n        * [The `vars/buildVmTemplate.groovy` functionality](#the-varsbuildvmtemplategroovy-functionality)\r\n    * [Other related/supporting information](#other-relatedsupporting-information)\r\n        * [To refresh template configurations using json sourced files](#to-refresh-template-configurations-using-json-sourced-files)\r\n        * [To Refresh/Update/Repair submodules](#to-refreshupdaterepair-submodules)\r\n        * [Use script to automate / simplify refreshing/repairing submodules](#use-script-to-automate--simplify-refreshingrepairing-submodules)\r\n    * [Reference](#reference)\r\n\r\n\r\n# Information/Notes on VM Template build automation\u003ca name=\"informationnotes-on-vm-template-build-automation\"\u003e\u003c/a\u003e \r\n\r\nThis project contains the Packer build configurations for vmware templates. \r\nEach template build configuration includes a minimal template definition for use with Vsphere. \r\n\r\n![vm-template-build-pipelines](./docs/img/vm-template-build-pipelines.drawio.svg)\r\n\r\nYou can also fork this repository and customize a build configuration with your own Ansible roles and playbooks to build a fully custom template using Packer. \r\n\r\n### GitHub Actions\r\n\r\n[![Template Validation](https://github.com/lj020326/vm-templates/actions/workflows/main.yml/badge.svg)](https://github.com/lj020326/vm-templates/actions/workflows/main.yml)\r\n[![License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](LICENSE)\r\n\r\n## Requirements\r\n\r\nThe following software must be installed/present on your local machine before you can use Packer to build any of these Vagrant templatees:\r\n\r\n  - [Packer](http://www.packer.io/)\r\n  - [Ansible](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html)\r\n\r\nI use docker containers for my jenkins build agents which have ansible and packer already installed.\r\nThe [specification for the docker agent container image can be found here](https://github.com/lj020326/jenkins-docker-agent/blob/master/image/jenkins-cicd-agent/Dockerfile).\r\nThe container leverages the 'jenkins/inbound-agent' image and the [cicd-build-tool image defined here](https://github.com/lj020326/jenkins-docker-agent/blob/master/image/cicd-build-tools/Dockerfile). \r\n\r\n## 1 - VM Template Build Definition Repository\u003ca name=\"1-vm-template-build-definition-repository\"\u003e\u003c/a\u003e \r\n\r\nThe vm template repository can be found at:\r\n    https://github.com/lj020326/vm-templates\r\n\r\n## 1.1 - VM Template Build Configurations\u003ca name=\"1-vm-template-build-configurations\"\u003e\u003c/a\u003e \r\n\r\nDetailed information for the [template build configuration parameters and options can be found here](./docs/configuration.md).\r\n\r\n## 2 - VM Template Build Automation from Jenkins\u003ca name=\"2-vm-template-build-automation-from-jenkins\"\u003e\u003c/a\u003e \r\n\r\nAll vm template builds are launched using jenkins pipeline jobs.\r\n\r\nThe jenkins controller docker instance is setup using the __jenkins config-as-code (jcac) plugin__ to automate the creation of all demo pipelines.\r\n\r\nThe jenkins pipeline repository can be found at:\r\n    https://github.com/lj020326/pipeline-automation-lib\r\n\r\nAll the jenkins projects and job pipelines are created from the job dsl script files in the folder at:\r\n    https://github.com/lj020326/pipeline-automation-lib/tree/main/jobs/jobdsl/templates\r\n\r\nThe job dsl script file used to create all the vm build pipeline jobs is at:\r\n    https://github.com/lj020326/pipeline-automation-lib/blob/main/jobs/jobdsl/templates/01_INFRA/init02_vm_templates.groovy\r\n\r\n\r\n### Jenkins Project Configurations stored in YAML file format\u003ca name=\"jenkins-project-configurations-stored-in-yaml-file-format\"\u003e\u003c/a\u003e \r\n\r\nEach jenkins infrastructure project folder has the respective configuration state stored in corresponding YAML files seen in the top level folder:\r\nhttps://github.com/lj020326/pipeline-automation-lib/tree/main/jobs/jobdsl/templates/01_INFRA\r\n\r\nAs an example see the configuration for the vm-template pipelines at:\r\nhttps://github.com/lj020326/pipeline-automation-lib/blob/main/jobs/jobdsl/templates/01_INFRA/config.vm-template-jobs.yml\r\n\r\n## 3 - Ansible role to setup docker jenkins control node\u003ca name=\"3-ansible-role-to-setup-docker-jenkins-control-node\"\u003e\u003c/a\u003e \r\n\r\nAn ansible role is used to setup all docker stack instances.\r\n\r\nThe `bootstrap_docker_stack` ansible role used to stand up the docker stack [can be found here](https://github.com/lj020326/ansible-datacenter/tree/main/roles/bootstrap_docker_stack).\r\n\r\nThe [`bootstrap_docker_stack` ansible role](https://github.com/lj020326/ansible-datacenter/tree/main/roles/bootstrap_docker_stack) contains the [__jenkins config-as-code (jcac) yaml definition__](https://github.com/lj020326/ansible-datacenter/blob/main/roles/bootstrap_docker_stack/templates/jenkins_jcac/jenkins_casc.yml.j2) in template form used to setup the jenkins jcac instance.\r\n\r\n[The jcac definition can be found here](https://github.com/lj020326/ansible-datacenter/blob/main/roles/bootstrap_docker_stack/templates/jenkins_jcac/jenkins_casc.yml.j2).  \r\n\r\n### Setup pipeline automation library used by all jenkins jobs\u003ca name=\"setup-pipeline-automation-library-used-by-all-jenkins-jobs\"\u003e\u003c/a\u003e \r\n\r\nThe pipeline automation library used can be found [here](https://github.com/lj020326/pipeline-automation-lib).\r\n[The pipeline automation library](https://github.com/lj020326/pipeline-automation-lib) defines the shared jenkins templates that are used throughout all of the jenkins ansible pipelines.  \r\n\r\nConfigure the library in jenkins as seen below.\r\n![Jenkins - Configure shared Pipeline Automation Library](./docs/img/screenshots/packer-templates-00-pipeline-library.png)\r\n\r\n\r\n### Site Root folder\r\n\r\nA root folder for the packer-templates environment can be setup similar to the following.\r\n![Site Root](./docs/img/screenshots/packer-templates-0-toplevel.png)\r\n\r\n### VM Packer Template OS folders\r\n\r\nThen setup folders for each VM OS defined as follows.\r\n![Site Environments](./docs/img/screenshots/packer-templates-1a-os.png)\r\n\r\n\r\n### VM Packer Template OS Version folders\r\n\r\nThen setup folders for each VM OS Version defined as follows.\r\n![Site Environments](./docs/img/screenshots/packer-templates-1a-os-versions.png)\r\n![Site Environments](./docs/img/screenshots/packer-templates-1a-os-version-builds.png)\r\n\r\n### VM Packer Template builder pipeline folders\r\n\r\nFor each template build node at the leaf level, setup a jenkins folder to run the groovy pipeline wrapper used to start the packer VM template builder process.\r\n\r\nThe folder definition for each VM template build folder should be as follows.\r\n![Build Template Pipeline Folders](./docs/img/screenshots/packer-templates-1a-template-build-wrapper.png)\r\n\r\nSee the job console for the VM packer template build pipeline output.\r\n![Job Console Output](./docs/img/screenshots/packer-templates-1a-template-build-output.png)\r\n\r\nThe detailed [pipeline job console output](./docs/jenkins-consoleText-packer-build-ubuntu-log.md).\r\n\r\n### Setup job to run all build template pipelines\r\n\r\nThen setup a pipeline job at the top level folder to run the [runAllBuilds.groovy](./runAllBuilds.groovy) as seen below.\r\n![Job Definition](./docs/img/screenshots/packer-templates-2a-run-all-builds-config.png)\r\n\r\nThis job will launch all of the VM template build jobs defined in [runAllBuilds.groovy](./runAllBuilds.groovy) with output similar to below.\r\n![Job Console Output](./docs/img/screenshots/packer-templates-2b-run-all-builds-output.png)\r\n\r\n## To repair submodule\r\n\r\n### for public/github branch\r\n\r\n```shell\r\n$ git switch github\r\n$ git submodule deinit -f .\r\n$ git submodule add --force --name ansible-github https://github.com/lj020326/ansible-datacenter.git ansible/\r\n$ git submodule update --init --recursive --remote\r\n$ git add . \u0026\u0026 git commit -m 'update submodule' \u0026\u0026 git push\r\n```\r\n\r\n## for master branch\r\n```shell\r\n$ git switch master\r\n$ git submodule deinit -f .\r\n$ git submodule add --force --name ansible git@bitbucket.org:lj020326/ansible-datacenter.git ansible/\r\n$ git submodule update --init --recursive --remote\r\n$ git add . \u0026\u0026 git commit -m 'update submodule' \u0026\u0026 git push\r\n```\r\n\r\n### To run/debug a script provisioner\r\n\r\n```shell\r\nsudo -S -E bash /tmp/script_4278.sh\r\n```\r\n\r\n### To run/debug the VM template create playbook on packer created VM\r\n\r\n```shell\r\n# find the temp dir used for the ansible-local provisioner from the packer log \r\n$ cd /tmp/packer-provisioner-ansible-local/63b193ab-d1c4-b355-f4cf-9e9153570896\r\n$ ansible-playbook bootstrap_vm_template.yml --vault-password-file=~/.vault_pass --limit vm_template -e @./vars/vault.yml -c local -i hosts.yml\r\n```\r\n\r\n## Other related/supporting information\u003ca name=\"other-relatedsupporting-information\"\u003e\u003c/a\u003e \r\n\r\n### To refresh template configurations using json sourced files\u003ca name=\"to-refresh-template-configurations-using-json-sourced-files\"\u003e\u003c/a\u003e \r\n\r\nTo refresh template json configuration using the source json files:\r\n```shell\r\n$ alias gitpullsub=\"git submodule update --recursive --remote\"\r\n$ alias gitmergesub=\"git submodule update --remote --merge \u0026\u0026 gitaddcommitpush\"\r\n$ templates/config.sh \r\n$ gitaddcommitpush\r\n```\r\n\r\n### To Refresh/Update/Repair submodules\u003ca name=\"to-refreshupdaterepair-submodules\"\u003e\u003c/a\u003e \r\n\r\n```shell\r\n$ alias gitpullsub=\"git submodule update --recursive --remote\"\r\n$ alias gitmergesub=\"git submodule update --remote --merge \u0026\u0026 gitaddcommitpush\"\r\n$ gitmergesub\r\n$ git status\r\n$ gitaddcommitpush ## git pull origin \u0026\u0026 git add . \u0026\u0026 git commit -m get-git-comment \u0026\u0026 git push origin\r\n```\r\n\r\n### Use script to automate / simplify refreshing/repairing submodules\u003ca name=\"use-script-to-automate-simplify-refreshingrepairing-submodules\"\u003e\u003c/a\u003e \r\n\r\nRun the utility bash script [`refresh-submodules.sh`](refresh-submodules.sh) found in the PROJECT root directory.\r\n\r\n```shell\r\n$ ./refresh-submodules.sh \r\n```\r\n\r\n## Notes, Considerations \u0026 Final Thoughts...\r\n\r\nIf defining the ansible playbooks as a submodule the same way done in this repo, make sure that the git repo option to \"Recursively update submodules\" is set/checked.\r\n\r\n## Reference\r\n\r\n- https://github.com/vmware-samples\r\n- https://github.com/vmware-samples/packer-examples-for-vsphere\r\n- https://www.hashicorp.com/blog/using-template-files-with-hashicorp-packer\r\n- https://github.com/chef/bento\r\n- https://github.com/burkeazbill/ubuntu-22-04-packer-fusion-workstation/blob/master/http/user-data\r\n- https://github.com/williamsanmartin/packer-template-ubuntu/blob/main/http/user-data\r\n- [vagrant-template-templates](https://github.com/mrlesmithjr/vagrant-template-templates)\r\n- https://github.com/mwrock/packer-templates\r\n- https://github.com/jacqinthetemplate/packer-templates\r\n- https://github.com/geerlingguy/packer-templates\r\n\r\n## Contact\r\n\r\n[![Linkedin](https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge\u0026logo=linkedin\u0026logoColor=white)](https://www.linkedin.com/in/leejjohnson/)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flj020326%2Fvm-templates","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flj020326%2Fvm-templates","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flj020326%2Fvm-templates/lists"}