From ea316f8e513fafa6bc68163c3a14d8dbafa08666 Mon Sep 17 00:00:00 2001 From: Mira <86979912+mira-miracoli@users.noreply.github.com> Date: Tue, 15 Oct 2024 10:20:52 +0200 Subject: [PATCH 1/6] use playbook variable in ansible packer --- templates/build.pkr.hcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/build.pkr.hcl b/templates/build.pkr.hcl index 927dba9..9131880 100644 --- a/templates/build.pkr.hcl +++ b/templates/build.pkr.hcl @@ -108,7 +108,7 @@ build { } provisioner "ansible" { - playbook_file = "ansible/all-playbooks.yml" + playbook_file = "${local.playbook}" user = "root" galaxy_file = "requirements.yml" roles_path = "ansible/roles/" From e178d4cf0965587753ea0165b007ed2b96084e1a Mon Sep 17 00:00:00 2001 From: Mira <86979912+mira-miracoli@users.noreply.github.com> Date: Tue, 15 Oct 2024 10:25:17 +0200 Subject: [PATCH 2/6] select playbook based on group --- templates/variables.pkr.hcl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/templates/variables.pkr.hcl b/templates/variables.pkr.hcl index 5ddfbdc..784ef4c 100644 --- a/templates/variables.pkr.hcl +++ b/templates/variables.pkr.hcl @@ -26,6 +26,9 @@ variable "headless" { type = string default = "true" } +locals { + playbook = contains(var.groups, "internal") ? "playbooks-internal.yml" : "playbooks-external.yml" +} locals { vault_password = contains(var.groups, "internal") ? "--vault-password-file=${var.vault_password_file}" : null } From fa80cd4bdddc9c973aae7de87bcfe1120bde0426 Mon Sep 17 00:00:00 2001 From: Mira <86979912+mira-miracoli@users.noreply.github.com> Date: Tue, 15 Oct 2024 10:29:25 +0200 Subject: [PATCH 3/6] Create playbooks-internal.yml --- ansible/playbooks-internal.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 ansible/playbooks-internal.yml diff --git a/ansible/playbooks-internal.yml b/ansible/playbooks-internal.yml new file mode 100644 index 0000000..24e5242 --- /dev/null +++ b/ansible/playbooks-internal.yml @@ -0,0 +1,20 @@ +# Meta-playbook for internal images that just imports all other playbooks. +# This Meta-playbook is selected when packer finds 'internal' in the group names. +# Requires a --vault-password-file=.vault_password argument in packer. +# +# It defines the order in which playbooks should be run during the provisioning +# step. Each playbook contains plays that only apply to hosts belonging to a +# group with the same name. Therefore, individual playbooks can be turned on +# and off via the "groups" variable defined in "templates/variables.pkr.hcl", +# which can also be overriden form the command line each time packer is +# launched. +--- +- ansible.builtin.import_playbook: generic.yml + +- ansible.builtin.import_playbook: workers.yml + +- ansible.builtin.import_playbook: workers-gpu.yml + +- ansible.builtin.import_playbook: jenkins.yml + +- ansible.builtin.import_playbook: internal.yml From a5414ea1ad93a67d6b78bbd8f149f9903b1a9bcd Mon Sep 17 00:00:00 2001 From: Mira <86979912+mira-miracoli@users.noreply.github.com> Date: Tue, 15 Oct 2024 10:31:27 +0200 Subject: [PATCH 4/6] Update and rename all-playbooks.yml to playbooks-external.yml --- ansible/{all-playbooks.yml => playbooks-external.yml} | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) rename ansible/{all-playbooks.yml => playbooks-external.yml} (81%) diff --git a/ansible/all-playbooks.yml b/ansible/playbooks-external.yml similarity index 81% rename from ansible/all-playbooks.yml rename to ansible/playbooks-external.yml index 26cdd0d..d0ae45c 100644 --- a/ansible/all-playbooks.yml +++ b/ansible/playbooks-external.yml @@ -1,4 +1,5 @@ -# Meta-playbook that just imports all other playbooks. +# Meta-playbook for external builds that just imports all other playbooks. +# Packer selects this playbook if 'internal' is not in the group names. # # It defines the order in which playbooks should be run during the provisioning # step. Each playbook contains plays that only apply to hosts belonging to a @@ -15,6 +16,4 @@ - ansible.builtin.import_playbook: jenkins.yml -- ansible.builtin.import_playbook: internal.yml - - ansible.builtin.import_playbook: external.yml From 218cb1bbfea1b1095c33643d7bac06c3c41795a9 Mon Sep 17 00:00:00 2001 From: Mira <86979912+mira-miracoli@users.noreply.github.com> Date: Tue, 15 Oct 2024 10:38:46 +0200 Subject: [PATCH 5/6] missing the directory --- templates/build.pkr.hcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/build.pkr.hcl b/templates/build.pkr.hcl index 9131880..81724af 100644 --- a/templates/build.pkr.hcl +++ b/templates/build.pkr.hcl @@ -108,7 +108,7 @@ build { } provisioner "ansible" { - playbook_file = "${local.playbook}" + playbook_file = "ansible/${local.playbook}" user = "root" galaxy_file = "requirements.yml" roles_path = "ansible/roles/" From 6dccb2f22ba67b49f39fd2822923a78290e152f0 Mon Sep 17 00:00:00 2001 From: Mira <86979912+mira-miracoli@users.noreply.github.com> Date: Tue, 15 Oct 2024 10:51:50 +0200 Subject: [PATCH 6/6] update rocky-9-latest checksum --- templates/build.pkr.hcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/build.pkr.hcl b/templates/build.pkr.hcl index 81724af..b045763 100644 --- a/templates/build.pkr.hcl +++ b/templates/build.pkr.hcl @@ -95,7 +95,7 @@ build { name = "rockylinux-9-latest-x86_64" vm_name = "rockylinux-9-latest-x86_64" iso_url = "https://download.rockylinux.org/pub/rocky/9/isos/x86_64/Rocky-9-latest-x86_64-boot.iso" - iso_checksum = "sha256:eb096f0518e310f722d5ebd4c69f0322df4fc152c6189f93c5c797dc25f3d2e1" + iso_checksum = "sha256:c7e95e3dba88a1f68fff8b7d4e66adf6f76ac4fba2e246a83c46ab79574c78a8" disk_size = "${local.disk_size}" boot_command = [ "",