From ac74c86f27d1155767caeb9c8227317baaefeec1 Mon Sep 17 00:00:00 2001 From: SNeef Date: Mon, 23 Jun 2025 14:27:42 +0200 Subject: [PATCH 1/5] Use hcl instead of .json --- .github/workflows/packer.yaml | 2 +- packer/bambichecker.hcl | 44 +++++++++++++++++++++++++++++++++++ packer/bambielk.hcl | 44 +++++++++++++++++++++++++++++++++++ packer/bambiengine.hcl | 44 +++++++++++++++++++++++++++++++++++ packer/bambirouter.hcl | 44 +++++++++++++++++++++++++++++++++++ packer/bambivulnbox.hcl | 44 +++++++++++++++++++++++++++++++++++ 6 files changed, 221 insertions(+), 1 deletion(-) create mode 100644 packer/bambichecker.hcl create mode 100644 packer/bambielk.hcl create mode 100644 packer/bambiengine.hcl create mode 100644 packer/bambirouter.hcl create mode 100644 packer/bambivulnbox.hcl diff --git a/.github/workflows/packer.yaml b/.github/workflows/packer.yaml index fe3f31b..17c7bae 100644 --- a/.github/workflows/packer.yaml +++ b/.github/workflows/packer.yaml @@ -114,7 +114,7 @@ jobs: - name: prepare ansible config run: docker compose exec -T bambictf sh -c 'cp ansible/config_bambi.yml.sample ansible/config_bambi.yml' - name: build packer image - run: docker compose exec -T bambictf sh -c 'cd packer; packer build ${{ matrix.image }}.json' + run: docker compose exec -T bambictf sh -c 'cd packer; packer build ${{ matrix.image }}.hcl' terraform-apply: runs-on: ubuntu-latest diff --git a/packer/bambichecker.hcl b/packer/bambichecker.hcl new file mode 100644 index 0000000..48327b2 --- /dev/null +++ b/packer/bambichecker.hcl @@ -0,0 +1,44 @@ +packer { + required_plugins { + hcloud = { + version = ">= 1.0.0" + source = "github.com/hetznercloud/hcloud" + } + } +} + +variable "snapshot_timestamp" { + type = string + default = timestamp() +} + +source "hcloud" "bambichecker" { + image = "ubuntu-24.04" + location = "fsn1" + server_type = "cx22" + ssh_username = "root" + snapshot_name = "bambichecker-${var.snapshot_timestamp}" + snapshot_labels = { + type = "bambichecker" + } + temporary_key_pair_type = "ecdsa" +} + +build { + name = "bambichecker" + + sources = [ + "source.hcloud.bambichecker" + ] + + provisioner "ansible" { + playbook_file = "../ansible/bambichecker.yml" + host_alias = "packer-checker" + ansible_env_vars = [ + "ANSIBLE_PIPELINING=True" + ] + extra_arguments = [ + "--scp-extra-args", "'-O'" + ] + } +} \ No newline at end of file diff --git a/packer/bambielk.hcl b/packer/bambielk.hcl new file mode 100644 index 0000000..aac8a57 --- /dev/null +++ b/packer/bambielk.hcl @@ -0,0 +1,44 @@ +packer { + required_plugins { + hcloud = { + version = ">= 1.0.0" + source = "github.com/hetznercloud/hcloud" + } + } +} + +variable "snapshot_timestamp" { + type = string + default = timestamp() +} + +source "hcloud" "bambielk" { + image = "ubuntu-24.04" + location = "fsn1" + server_type = "cx22" + ssh_username = "root" + snapshot_name = "bambielk-${var.snapshot_timestamp}" + snapshot_labels = { + type = "bambielk" + } + temporary_key_pair_type = "ecdsa" +} + +build { + name = "bambielk" + + sources = [ + "source.hcloud.bambielk" + ] + + provisioner "ansible" { + playbook_file = "../ansible/bambielk.yml" + host_alias = "packer-elk" + ansible_env_vars = [ + "ANSIBLE_PIPELINING=True" + ] + extra_arguments = [ + "--scp-extra-args", "'-O'" + ] + } +} \ No newline at end of file diff --git a/packer/bambiengine.hcl b/packer/bambiengine.hcl new file mode 100644 index 0000000..de494de --- /dev/null +++ b/packer/bambiengine.hcl @@ -0,0 +1,44 @@ +packer { + required_plugins { + hcloud = { + version = ">= 1.0.0" + source = "github.com/hetznercloud/hcloud" + } + } +} + +variable "snapshot_timestamp" { + type = string + default = timestamp() +} + +source "hcloud" "bambiengine" { + image = "ubuntu-24.04" + location = "fsn1" + server_type = "cx22" + ssh_username = "root" + snapshot_name = "bambiengine-${var.snapshot_timestamp}" + snapshot_labels = { + type = "bambiengine" + } + temporary_key_pair_type = "ecdsa" +} + +build { + name = "bambiengine" + + sources = [ + "source.hcloud.bambiengine" + ] + + provisioner "ansible" { + playbook_file = "../ansible/bambiengine.yml" + host_alias = "packer-engine" + ansible_env_vars = [ + "ANSIBLE_PIPELINING=True" + ] + extra_arguments = [ + "--scp-extra-args", "'-O'" + ] + } +} \ No newline at end of file diff --git a/packer/bambirouter.hcl b/packer/bambirouter.hcl new file mode 100644 index 0000000..a90cbb4 --- /dev/null +++ b/packer/bambirouter.hcl @@ -0,0 +1,44 @@ +packer { + required_plugins { + hcloud = { + version = ">= 1.0.0" + source = "github.com/hetznercloud/hcloud" + } + } +} + +variable "snapshot_timestamp" { + type = string + default = timestamp() +} + +source "hcloud" "bambirouter" { + image = "ubuntu-24.04" + location = "fsn1" + server_type = "cx22" + ssh_username = "root" + snapshot_name = "bambirouter-${var.snapshot_timestamp}" + snapshot_labels = { + type = "bambirouter" + } + temporary_key_pair_type = "ecdsa" +} + +build { + name = "bambirouter" + + sources = [ + "source.hcloud.bambirouter" + ] + + provisioner "ansible" { + playbook_file = "../ansible/bambirouter.yml" + host_alias = "packer-router" + ansible_env_vars = [ + "ANSIBLE_PIPELINING=True" + ] + extra_arguments = [ + "--scp-extra-args", "'-O'" + ] + } +} \ No newline at end of file diff --git a/packer/bambivulnbox.hcl b/packer/bambivulnbox.hcl new file mode 100644 index 0000000..b315daf --- /dev/null +++ b/packer/bambivulnbox.hcl @@ -0,0 +1,44 @@ +packer { + required_plugins { + hcloud = { + version = ">= 1.0.0" + source = "github.com/hetznercloud/hcloud" + } + } +} + +variable "snapshot_timestamp" { + type = string + default = timestamp() +} + +source "hcloud" "bambivulnbox" { + image = "ubuntu-24.04" + location = "fsn1" + server_type = "cx32" + ssh_username = "root" + snapshot_name = "bambivulnbox-${var.snapshot_timestamp}" + snapshot_labels = { + type = "bambivulnbox" + } + temporary_key_pair_type = "ecdsa" +} + +build { + name = "bambivulnbox" + + sources = [ + "source.hcloud.bambivulnbox" + ] + + provisioner "ansible" { + playbook_file = "../ansible/bambivulnbox.yml" + host_alias = "packer-vulnbox" + extra_arguments = [ + "--scp-extra-args", "'-O'" + ] + ansible_env_vars = [ + "ANSIBLE_PIPELINING=True" + ] + } +} \ No newline at end of file From 1e95ed645fa457c8e624a8d8f60f9cad60010183 Mon Sep 17 00:00:00 2001 From: SNeef Date: Mon, 23 Jun 2025 14:43:42 +0200 Subject: [PATCH 2/5] Use correct extension: *.pkr.hcl --- packer/{bambichecker.hcl => bambichecker.pkr.hcl} | 0 packer/{bambielk.hcl => bambielk.pkr.hcl} | 0 packer/{bambiengine.hcl => bambiengine.pkr.hcl} | 0 packer/{bambirouter.hcl => bambirouter.pkr.hcl} | 0 packer/{bambivulnbox.hcl => bambivulnbox.pkr.hcl} | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename packer/{bambichecker.hcl => bambichecker.pkr.hcl} (100%) rename packer/{bambielk.hcl => bambielk.pkr.hcl} (100%) rename packer/{bambiengine.hcl => bambiengine.pkr.hcl} (100%) rename packer/{bambirouter.hcl => bambirouter.pkr.hcl} (100%) rename packer/{bambivulnbox.hcl => bambivulnbox.pkr.hcl} (100%) diff --git a/packer/bambichecker.hcl b/packer/bambichecker.pkr.hcl similarity index 100% rename from packer/bambichecker.hcl rename to packer/bambichecker.pkr.hcl diff --git a/packer/bambielk.hcl b/packer/bambielk.pkr.hcl similarity index 100% rename from packer/bambielk.hcl rename to packer/bambielk.pkr.hcl diff --git a/packer/bambiengine.hcl b/packer/bambiengine.pkr.hcl similarity index 100% rename from packer/bambiengine.hcl rename to packer/bambiengine.pkr.hcl diff --git a/packer/bambirouter.hcl b/packer/bambirouter.pkr.hcl similarity index 100% rename from packer/bambirouter.hcl rename to packer/bambirouter.pkr.hcl diff --git a/packer/bambivulnbox.hcl b/packer/bambivulnbox.pkr.hcl similarity index 100% rename from packer/bambivulnbox.hcl rename to packer/bambivulnbox.pkr.hcl From 9ac8333c8d7ff3e82c2f3e70c98eb3802a4fd1ee Mon Sep 17 00:00:00 2001 From: SNeef Date: Mon, 23 Jun 2025 14:52:47 +0200 Subject: [PATCH 3/5] Use correct extension in the workflow --- .github/workflows/packer.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/packer.yaml b/.github/workflows/packer.yaml index 17c7bae..891dbda 100644 --- a/.github/workflows/packer.yaml +++ b/.github/workflows/packer.yaml @@ -114,7 +114,7 @@ jobs: - name: prepare ansible config run: docker compose exec -T bambictf sh -c 'cp ansible/config_bambi.yml.sample ansible/config_bambi.yml' - name: build packer image - run: docker compose exec -T bambictf sh -c 'cd packer; packer build ${{ matrix.image }}.hcl' + run: docker compose exec -T bambictf sh -c 'cd packer; packer build ${{ matrix.image }}.pkr.hcl' terraform-apply: runs-on: ubuntu-latest From ab690e5deb0c94746cdfaf9c9c52e5a33bfa5366 Mon Sep 17 00:00:00 2001 From: SNeef Date: Mon, 23 Jun 2025 15:38:08 +0200 Subject: [PATCH 4/5] Use locals instead of variable --- packer/bambichecker.pkr.hcl | 7 +++---- packer/bambielk.pkr.hcl | 7 +++---- packer/bambiengine.pkr.hcl | 7 +++---- packer/bambirouter.pkr.hcl | 7 +++---- packer/bambivulnbox.pkr.hcl | 7 +++---- 5 files changed, 15 insertions(+), 20 deletions(-) diff --git a/packer/bambichecker.pkr.hcl b/packer/bambichecker.pkr.hcl index 48327b2..2df47bd 100644 --- a/packer/bambichecker.pkr.hcl +++ b/packer/bambichecker.pkr.hcl @@ -7,9 +7,8 @@ packer { } } -variable "snapshot_timestamp" { - type = string - default = timestamp() +locals { + snapshot_timestamp = timestamp() } source "hcloud" "bambichecker" { @@ -17,7 +16,7 @@ source "hcloud" "bambichecker" { location = "fsn1" server_type = "cx22" ssh_username = "root" - snapshot_name = "bambichecker-${var.snapshot_timestamp}" + snapshot_name = "bambichecker-${local.snapshot_timestamp}" snapshot_labels = { type = "bambichecker" } diff --git a/packer/bambielk.pkr.hcl b/packer/bambielk.pkr.hcl index aac8a57..1d32f62 100644 --- a/packer/bambielk.pkr.hcl +++ b/packer/bambielk.pkr.hcl @@ -7,9 +7,8 @@ packer { } } -variable "snapshot_timestamp" { - type = string - default = timestamp() +locals { + snapshot_timestamp = timestamp() } source "hcloud" "bambielk" { @@ -17,7 +16,7 @@ source "hcloud" "bambielk" { location = "fsn1" server_type = "cx22" ssh_username = "root" - snapshot_name = "bambielk-${var.snapshot_timestamp}" + snapshot_name = "bambielk-${local.snapshot_timestamp}" snapshot_labels = { type = "bambielk" } diff --git a/packer/bambiengine.pkr.hcl b/packer/bambiengine.pkr.hcl index de494de..cd3e088 100644 --- a/packer/bambiengine.pkr.hcl +++ b/packer/bambiengine.pkr.hcl @@ -7,9 +7,8 @@ packer { } } -variable "snapshot_timestamp" { - type = string - default = timestamp() +locals { + snapshot_timestamp = timestamp() } source "hcloud" "bambiengine" { @@ -17,7 +16,7 @@ source "hcloud" "bambiengine" { location = "fsn1" server_type = "cx22" ssh_username = "root" - snapshot_name = "bambiengine-${var.snapshot_timestamp}" + snapshot_name = "bambiengine-${local.snapshot_timestamp}" snapshot_labels = { type = "bambiengine" } diff --git a/packer/bambirouter.pkr.hcl b/packer/bambirouter.pkr.hcl index a90cbb4..b570389 100644 --- a/packer/bambirouter.pkr.hcl +++ b/packer/bambirouter.pkr.hcl @@ -7,9 +7,8 @@ packer { } } -variable "snapshot_timestamp" { - type = string - default = timestamp() +locals { + snapshot_timestamp = timestamp() } source "hcloud" "bambirouter" { @@ -17,7 +16,7 @@ source "hcloud" "bambirouter" { location = "fsn1" server_type = "cx22" ssh_username = "root" - snapshot_name = "bambirouter-${var.snapshot_timestamp}" + snapshot_name = "bambirouter-${local.snapshot_timestamp}" snapshot_labels = { type = "bambirouter" } diff --git a/packer/bambivulnbox.pkr.hcl b/packer/bambivulnbox.pkr.hcl index b315daf..f248da4 100644 --- a/packer/bambivulnbox.pkr.hcl +++ b/packer/bambivulnbox.pkr.hcl @@ -7,9 +7,8 @@ packer { } } -variable "snapshot_timestamp" { - type = string - default = timestamp() +locals { + snapshot_timestamp = timestamp() } source "hcloud" "bambivulnbox" { @@ -17,7 +16,7 @@ source "hcloud" "bambivulnbox" { location = "fsn1" server_type = "cx32" ssh_username = "root" - snapshot_name = "bambivulnbox-${var.snapshot_timestamp}" + snapshot_name = "bambivulnbox-${local.snapshot_timestamp}" snapshot_labels = { type = "bambivulnbox" } From ed3372f67e5eed64eddde30b9e1d211aa197b820 Mon Sep 17 00:00:00 2001 From: SNeef Date: Mon, 23 Jun 2025 16:44:48 +0200 Subject: [PATCH 5/5] Run packer init --- .github/workflows/packer.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/packer.yaml b/.github/workflows/packer.yaml index 891dbda..2a1a6cc 100644 --- a/.github/workflows/packer.yaml +++ b/.github/workflows/packer.yaml @@ -114,7 +114,7 @@ jobs: - name: prepare ansible config run: docker compose exec -T bambictf sh -c 'cp ansible/config_bambi.yml.sample ansible/config_bambi.yml' - name: build packer image - run: docker compose exec -T bambictf sh -c 'cd packer; packer build ${{ matrix.image }}.pkr.hcl' + run: docker compose exec -T bambictf sh -c 'cd packer; packer init ${{ matrix.image }}.pkr.hcl; packer build ${{ matrix.image }}.pkr.hcl' terraform-apply: runs-on: ubuntu-latest