Table of Contents:
- Information/Notes on VM Template build automation
This project contains the Packer build configurations for vmware templates. Each template build configuration includes a minimal template definition for use with Vsphere.
You 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.
The following software must be installed/present on your local machine before you can use Packer to build any of these Vagrant templatees:
I use docker containers for my jenkins build agents which have ansible and packer already installed. The specification for the docker agent container image can be found here. The container leverages the 'jenkins/inbound-agent' image and the cicd-build-tool image defined here.
The vm template repository can be found at: https://github.com/lj020326/vm-templates
Detailed information for the template build configuration parameters and options can be found here.
All vm template builds are launched using jenkins pipeline jobs.
The jenkins controller docker instance is setup using the jenkins config-as-code (jcac) plugin to automate the creation of all demo pipelines.
The jenkins pipeline repository can be found at: https://github.com/lj020326/pipeline-automation-lib
All the jenkins projects and job pipelines are created from the job dsl script files in the folder at: https://github.com/lj020326/pipeline-automation-lib/tree/main/jobs/jobdsl/templates
The job dsl script file used to create all the vm build pipeline jobs is at: https://github.com/lj020326/pipeline-automation-lib/blob/main/jobs/jobdsl/templates/01_INFRA/init02_vm_templates.groovy
Each jenkins infrastructure project folder has the respective configuration state stored in corresponding YAML files seen in the top level folder: https://github.com/lj020326/pipeline-automation-lib/tree/main/jobs/jobdsl/templates/01_INFRA
As an example see the configuration for the vm-template pipelines at: https://github.com/lj020326/pipeline-automation-lib/blob/main/jobs/jobdsl/templates/01_INFRA/config.vm-template-jobs.yml
An ansible role is used to setup all docker stack instances.
The bootstrap_docker_stack
ansible role used to stand up the docker stack can be found here.
The bootstrap_docker_stack
ansible role contains the jenkins config-as-code (jcac) yaml definition in template form used to setup the jenkins jcac instance.
The jcac definition can be found here.
The pipeline automation library used can be found here. The pipeline automation library defines the shared jenkins templates that are used throughout all of the jenkins ansible pipelines.
Configure the library in jenkins as seen below.
A root folder for the packer-templates environment can be setup similar to the following.
Then setup folders for each VM OS defined as follows.
Then setup folders for each VM OS Version defined as follows.
For 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.
The folder definition for each VM template build folder should be as follows.
See the job console for the VM packer template build pipeline output.
The detailed pipeline job console output.
Then setup a pipeline job at the top level folder to run the runAllBuilds.groovy as seen below.
This job will launch all of the VM template build jobs defined in runAllBuilds.groovy with output similar to below.
$ git switch github
$ git submodule deinit -f .
$ git submodule add --force --name ansible-github https://github.com/lj020326/ansible-datacenter.git ansible/
$ git submodule update --init --recursive --remote
$ git add . && git commit -m 'update submodule' && git push
$ git switch master
$ git submodule deinit -f .
$ git submodule add --force --name ansible git@bitbucket.org:lj020326/ansible-datacenter.git ansible/
$ git submodule update --init --recursive --remote
$ git add . && git commit -m 'update submodule' && git push
sudo -S -E bash /tmp/script_4278.sh
# find the temp dir used for the ansible-local provisioner from the packer log
$ cd /tmp/packer-provisioner-ansible-local/63b193ab-d1c4-b355-f4cf-9e9153570896
$ ansible-playbook bootstrap_vm_template.yml --vault-password-file=~/.vault_pass --limit vm_template -e @./vars/vault.yml -c local -i hosts.yml
To refresh template json configuration using the source json files:
$ alias gitpullsub="git submodule update --recursive --remote"
$ alias gitmergesub="git submodule update --remote --merge && gitaddcommitpush"
$ templates/config.sh
$ gitaddcommitpush
$ alias gitpullsub="git submodule update --recursive --remote"
$ alias gitmergesub="git submodule update --remote --merge && gitaddcommitpush"
$ gitmergesub
$ git status
$ gitaddcommitpush ## git pull origin && git add . && git commit -m get-git-comment && git push origin
Run the utility bash script refresh-submodules.sh
found in the PROJECT root directory.
$ ./refresh-submodules.sh
If 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.
- https://github.com/vmware-samples
- https://github.com/vmware-samples/packer-examples-for-vsphere
- https://www.hashicorp.com/blog/using-template-files-with-hashicorp-packer
- https://github.com/chef/bento
- https://github.com/burkeazbill/ubuntu-22-04-packer-fusion-workstation/blob/master/http/user-data
- https://github.com/williamsanmartin/packer-template-ubuntu/blob/main/http/user-data
- vagrant-template-templates
- https://github.com/mwrock/packer-templates
- https://github.com/jacqinthetemplate/packer-templates
- https://github.com/geerlingguy/packer-templatees