From 3b5b4e7342dfcb1a876ec8abe2264012818ce3c0 Mon Sep 17 00:00:00 2001
From: Eesaan Atluri <atlurie@uab.edu>
Date: Mon, 26 Jun 2023 13:05:13 -0500
Subject: [PATCH] Allow using RSA keys when packer ssh communicator tries to
 ssh.

Latest versions of packer removed ssh-rsa keys from accepted methods of
publickey auth. This commit is a workaround to allow ssh-rsa to be used
for ssh by packer communicator to ssh into build instance.
This should be fixed in the upcoming iterations to use correct methods
like ssh-ecdsa etc.
---
 openstack-compute/nodeimage.pkr.hcl | 5 +++++
 openstack-gpu/nodeimage.pkr.hcl     | 5 +++++
 openstack/nodeimage.pkr.hcl         | 5 +++++
 3 files changed, 15 insertions(+)

diff --git a/openstack-compute/nodeimage.pkr.hcl b/openstack-compute/nodeimage.pkr.hcl
index e6f39d8a..c10e095f 100644
--- a/openstack-compute/nodeimage.pkr.hcl
+++ b/openstack-compute/nodeimage.pkr.hcl
@@ -25,8 +25,13 @@ build {
   provisioner "ansible" {
     groups = ["compute"]
     playbook_file = "./ansible/compute.yml"
+    ansible_env_vars = [
+      "ANSIBLE_SSH_ARGS='-oHostKeyAlgorithms=+ssh-rsa -oPubkeyAcceptedKeyTypes=ssh-rsa'",
+      "ANSIBLE_HOST_KEY_CHECKING=False"
+    ]
     roles_path = "./ansible/roles"
     extra_arguments = [
+      "--scp-extra-args", "'-O'",
       "--extra-vars", "root_ssh_key='${var.root_ssh_key}'"
     ]
   }
diff --git a/openstack-gpu/nodeimage.pkr.hcl b/openstack-gpu/nodeimage.pkr.hcl
index 02720c2d..7d3ed258 100644
--- a/openstack-gpu/nodeimage.pkr.hcl
+++ b/openstack-gpu/nodeimage.pkr.hcl
@@ -21,8 +21,13 @@ build {
   provisioner "ansible" {
     groups = ["gpu"]
     playbook_file = "./ansible/gpu.yml"
+    ansible_env_vars = [
+      "ANSIBLE_SSH_ARGS='-oHostKeyAlgorithms=+ssh-rsa -oPubkeyAcceptedKeyTypes=ssh-rsa'",
+      "ANSIBLE_HOST_KEY_CHECKING=False"
+    ]
     roles_path = "./ansible/roles"
     extra_arguments = [
+      "--scp-extra-args", "'-O'",
       "--extra-vars", "root_ssh_key='${var.root_ssh_key}'"
     ]
   }
diff --git a/openstack/nodeimage.pkr.hcl b/openstack/nodeimage.pkr.hcl
index 509ae3cd..7988088e 100644
--- a/openstack/nodeimage.pkr.hcl
+++ b/openstack/nodeimage.pkr.hcl
@@ -26,8 +26,13 @@ build {
     user = var.ssh_username
     groups = ["base"]
     playbook_file = "./ansible/base.yml"
+    ansible_env_vars = [
+      "ANSIBLE_SSH_ARGS='-oHostKeyAlgorithms=+ssh-rsa -oPubkeyAcceptedKeyTypes=ssh-rsa'",
+      "ANSIBLE_HOST_KEY_CHECKING=False"
+    ]
     roles_path = "./ansible/roles"
     extra_arguments = [
+      "--scp-extra-args", "'-O'",
       "--extra-vars", "root_ssh_key='${var.root_ssh_key}'"
     ]
   }
-- 
GitLab