Skip to content

Commit

Permalink
feat(packer/bake-callable-update): add custom host config path as a n…
Browse files Browse the repository at this point in the history
…ew cli-option (#277)

* doc(packer-template): added quick-use guide

* feat(packer-template): add custom host config path as a new cli-option
  • Loading branch information
piyoki authored Jan 14, 2023
1 parent 3541232 commit 8d2a12d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
16 changes: 16 additions & 0 deletions packer-templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,22 @@ There is a dedicated blog post for the basic/advanced use cases using this Packe

![](https://github.com/TechProber/cloud-estate/blob/master/packer-templates/assets/screenshot.png?raw=true)

## Quick Use

```bash
# check usage
./bake -h

# bake vm template
export HOST_CONFIG=[HOST_CONFIG]
export PACKER_VAR_FILE=[PACKER_VAR_FILE]
# e.g.
# export HOST_CONFIG=~/workspace/vsphere-hub/packer/config.json
# export PACKER_VAR_FILE=~/workspace/vsphere-hub/packer/vars/pve-03-ubuntu-2204.json

./bake -i 9000 -t cn-ubuntu-2204-server -n prod-ubuntu-2204-server-template -c $HOST_CONFIG -f $PACKER_VAR_FILE
```

## References

- [Creating proxmox templates with packer - Aaron Berry](https://dev.to/aaronktberry/creating-proxmox-templates-with-packer-1b35)
Expand Down
8 changes: 6 additions & 2 deletions packer-templates/bake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ build_type=
only=false
only_opt=
var_file=
host_config=

# Proxmox Builder

Expand Down Expand Up @@ -109,7 +110,9 @@ while getopts ":hai:t:n:b:f:d:" opt; do
n|--name) vm_name=$OPTARG;;
# specify custom-build build type
b|--build) build_type=$OPTARG;;
# specify packer var-file path
# specify host config path, e.g: ./config.json
c|--config) host_config=$OPTARG;;
# specify packer var-file path, e.g: ./vars/ubuntu-2204.json
f|--var-file) var_file=$OPTARG;;
# specify custom iso-data path
d|--iso-data) iso_data=$OPTARG;;
Expand All @@ -126,14 +129,15 @@ done
[[ ! -z "$build_type" ]] && template="${build_type}-custom-${template}" || template=$template
[[ ! -z "$build_type" ]] && build_type=$build_type || build_type="base"
[[ ! -z "$var_file" ]] && var_file=$var_file || var_file="./vars/ubuntu-2204.json"
[[ ! -z "$host_config" ]] && host_config=$host_config || host_config="./config.json"

# --- Main Operation --- #

echoW "Baking ${vm_name} template with packer\n"

packer build -force \
-var-file ${var_file} \
-var-file config.json \
-var-file ${host_config} \
-var playbook_file="playbooks/${vm_type}.yml" \
-var template_name=$vm_name \
-var proxmox_api_password=$PM_PASS \
Expand Down

0 comments on commit 8d2a12d

Please sign in to comment.