Skip to content

lj020326/vm-templates

Repository files navigation

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.

vm-template-build-pipelines

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.

GitHub Actions

Template Validation License

Requirements

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.

1 - VM Template Build Definition Repository

The vm template repository can be found at: https://github.com/lj020326/vm-templates

1.1 - VM Template Build Configurations

Detailed information for the template build configuration parameters and options can be found here.

2 - VM Template Build Automation from Jenkins

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

Jenkins Project Configurations stored in YAML file format

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

3 - Ansible role to setup docker jenkins control node

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.

Setup pipeline automation library used by all jenkins jobs

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. Jenkins - Configure shared Pipeline Automation Library

Site Root folder

A root folder for the packer-templates environment can be setup similar to the following. Site Root

VM Packer Template OS folders

Then setup folders for each VM OS defined as follows. Site Environments

VM Packer Template OS Version folders

Then setup folders for each VM OS Version defined as follows. Site Environments Site Environments

VM Packer Template builder pipeline folders

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. Build Template Pipeline Folders

See the job console for the VM packer template build pipeline output. Job Console Output

The detailed pipeline job console output.

Setup job to run all build template pipelines

Then setup a pipeline job at the top level folder to run the runAllBuilds.groovy as seen below. Job Definition

This job will launch all of the VM template build jobs defined in runAllBuilds.groovy with output similar to below. Job Console Output

To repair submodule

for public/github branch

$ 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

for master branch

$ 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

To run/debug a script provisioner

sudo -S -E bash /tmp/script_4278.sh

To run/debug the VM template create playbook on packer created VM

# 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

Other related/supporting information

To refresh template configurations using json sourced files

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

To Refresh/Update/Repair submodules

$ 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

Use script to automate / simplify refreshing/repairing submodules

Run the utility bash script refresh-submodules.sh found in the PROJECT root directory.

$ ./refresh-submodules.sh 

Notes, Considerations & Final Thoughts...

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.

Reference

Contact

Linkedin