Skip to contentSkip to conversation

Set kdevops_terraform_ssh_config_privkey_file unconditionally

PATCH Superseded Chandan Babu R 2 participants 9 messages May 2, 2025 – May 5, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 Set kdevops_terraform_ssh_config_privkey_file unconditionally

kdevops_terraform_ssh_config_privkey_file is not set on control systems which use pre-existing ssh keys. Hence, adding entries of provisioned cloud instances to the ephemeral ssh config file fails on such systems.

Fix this by setting kdevops_terraform_ssh_config_privkey_file unconditionally.

---
 scripts/terraform.Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/terraform.Makefile +1 -1
index 91469469..b6b26e69 100644
@@ -85,10 +85,10 @@ endif # CONFIG_KDEVOPS_SSH_CONFIG_UPDATE
 export KDEVOPS_SSH_PUBKEY:=$(shell realpath $(subst ",,$(CONFIG_TERRAFORM_SSH_CONFIG_PUBKEY_FILE)))
 TERRAFORM_EXTRA_VARS += kdevops_terraform_ssh_config_pubkey_file='$(KDEVOPS_SSH_PUBKEY)'
 TERRAFORM_EXTRA_VARS += kdevops_terraform_ssh_config_user='$(SSH_CONFIG_USER)'
+TERRAFORM_EXTRA_VARS += kdevops_terraform_ssh_config_privkey_file='$(basename $(KDEVOPS_SSH_PUBKEY))'
 
 ifeq (y,$(CONFIG_TERRAFORM_SSH_CONFIG_GENKEY))
 export KDEVOPS_SSH_PRIVKEY:=$(basename $(KDEVOPS_SSH_PUBKEY))
-TERRAFORM_EXTRA_VARS += kdevops_terraform_ssh_config_privkey_file='$(KDEVOPS_SSH_PRIVKEY)'
 
 ifeq (y,$(CONFIG_TERRAFORM_SSH_CONFIG_GENKEY_OVERWRITE))
 DEFAULT_DEPS += remove-ssh-key
Signature · 1 line
2.45.2
#1 lore raw

PATCH 2/3 Remove kdevops_terraform_ssh_config_genkey_overwrite

Adding entries to the ephemeral ssh config file on control systems is being done only when kdevops_terraform_ssh_config_genkey_overwrite evaluates to true. This is incorrect because we need to allow Kdevops to be used with pre-existing ssh keys. Hence remove the conditions in playbooks/roles/terraform/defaults/main.yml which check the value of kdevops_terraform_ssh_config_genkey_overwrite.

Also, the value of kdevops_terraform_ssh_config_genkey_overwrite is not checked in any other file. Hence this commit removes the remaining instances of this variable.

---
 playbooks/roles/terraform/defaults/main.yml | 1 -
 playbooks/roles/terraform/tasks/main.yml    | 8 --------
 scripts/terraform.Makefile                  | 1 -
 3 files changed, 10 deletions(-)
playbooks/roles/terraform/defaults/main.yml +0 -1
index f3ef9b18..33bd00e6 100644
@@ -1,3 +1,2 @@
 ---
 ssh_config_kexalgorithms: ""
-kdevops_terraform_ssh_config_genkey_overwrite: false
playbooks/roles/terraform/tasks/main.yml +0 -8
index 272ebf93..d04dc997 100644
@@ -15,8 +15,6 @@
     cmd: "terraform output -json public_ip_map"
   register: terraform_output
   changed_when: false
-  when:
-    - kdevops_terraform_ssh_config_genkey_overwrite|bool
   tags:
     - ssh
 
@@ -25,8 +23,6 @@
   run_once: true
   ansible.builtin.set_fact:
     public_ip_map: "{{ terraform_output.stdout | from_json }}"
-  when:
-    - kdevops_terraform_ssh_config_genkey_overwrite|bool
   tags:
     - ssh
 
@@ -40,8 +36,6 @@
     insertafter: "EOF"
     marker: "# {mark} host configuration for {{ inventory_hostname }}"
     mode: "u=rw,g=r,o=r"
-  when:
-    - kdevops_terraform_ssh_config_genkey_overwrite|bool
   tags:
     - ssh
 
@@ -55,8 +49,6 @@
     marker: "# {mark} Managed by kdevops"
     mode: "u=rw,g=r,o=r"
     block: "Include {{ kdevops_ssh_config_prefix }}*"
-  when:
-    - kdevops_terraform_ssh_config_genkey_overwrite|bool
   tags:
     - ssh
 
scripts/terraform.Makefile +0 -1
index b6b26e69..865c84c3 100644
@@ -92,7 +92,6 @@ export KDEVOPS_SSH_PRIVKEY:=$(basename $(KDEVOPS_SSH_PUBKEY))
 
 ifeq (y,$(CONFIG_TERRAFORM_SSH_CONFIG_GENKEY_OVERWRITE))
 DEFAULT_DEPS += remove-ssh-key
-TERRAFORM_EXTRA_VARS += kdevops_terraform_ssh_config_genkey_overwrite='True'
 endif
 
 DEFAULT_DEPS += $(KDEVOPS_SSH_PRIVKEY)
Signature · 1 line
2.45.2
Reviewed-by on v1 2/3
#2 lore raw

Re: [PATCH 2/3] Remove kdevops_terraform_ssh_config_genkey_overwrite

Quoted 71 lines · Chandan Babu R

Adding entries to the ephemeral ssh config file on control systems is being done only when kdevops_terraform_ssh_config_genkey_overwrite evaluates to true. This is incorrect because we need to allow Kdevops to be used with pre-existing ssh keys. Hence remove the conditions in playbooks/roles/terraform/defaults/main.yml which check the value of kdevops_terraform_ssh_config_genkey_overwrite.

Also, the value of kdevops_terraform_ssh_config_genkey_overwrite is not checked in any other file. Hence this commit removes the remaining instances of this variable.

---
 playbooks/roles/terraform/defaults/main.yml | 1 -
 playbooks/roles/terraform/tasks/main.yml    | 8 --------
 scripts/terraform.Makefile                  | 1 -
 3 files changed, 10 deletions(-)
playbooks/roles/terraform/defaults/main.yml +0 -1
index f3ef9b18..33bd00e6 100644
@@ -1,3 +1,2 @@
 ---
 ssh_config_kexalgorithms: ""
-kdevops_terraform_ssh_config_genkey_overwrite: false
playbooks/roles/terraform/tasks/main.yml +0 -8
index 272ebf93..d04dc997 100644
@@ -15,8 +15,6 @@
     cmd: "terraform output -json public_ip_map"
   register: terraform_output
   changed_when: false
-  when:
-    - kdevops_terraform_ssh_config_genkey_overwrite|bool
   tags:
     - ssh
 
@@ -25,8 +23,6 @@
   run_once: true
   ansible.builtin.set_fact:
     public_ip_map: "{{ terraform_output.stdout | from_json }}"
-  when:
-    - kdevops_terraform_ssh_config_genkey_overwrite|bool
   tags:
     - ssh
 
@@ -40,8 +36,6 @@
     insertafter: "EOF"
     marker: "# {mark} host configuration for {{ inventory_hostname }}"
     mode: "u=rw,g=r,o=r"
-  when:
-    - kdevops_terraform_ssh_config_genkey_overwrite|bool
   tags:
     - ssh
 
@@ -55,8 +49,6 @@
     marker: "# {mark} Managed by kdevops"
     mode: "u=rw,g=r,o=r"
     block: "Include {{ kdevops_ssh_config_prefix }}*"
-  when:
-    - kdevops_terraform_ssh_config_genkey_overwrite|bool
   tags:
     - ssh
 
scripts/terraform.Makefile +0 -0
index b6b26e69..865c84c3 100644

scripts/terraform.Makefile export KDEVOPS_SSH_PRIVKEY:=$(basename $(KDEVOPS_SSH_PUBKEY)) · line 97

Quoted 7 lines
scripts/terraform.Makefile +0 -1
@@ -92,7 +92,6 @@ export KDEVOPS_SSH_PRIVKEY:=$(basename $(KDEVOPS_SSH_PUBKEY))
 
 ifeq (y,$(CONFIG_TERRAFORM_SSH_CONFIG_GENKEY_OVERWRITE))
 DEFAULT_DEPS += remove-ssh-key
-TERRAFORM_EXTRA_VARS += kdevops_terraform_ssh_config_genkey_overwrite='True'
 endif
 
 DEFAULT_DEPS += $(KDEVOPS_SSH_PRIVKEY)
Signature · 1 line
Chuck Lever
#3 lore raw

PATCH 3/3 Allow private IP address to be assigned to instances created on OCI

In reply to Chandan Babu R

The OCI tenancy available to kernel developers from Oracle allows only private IP addresses to be assigned to compute instances. Hence this commit brings back the ability to work with OCI instances having private IP addresses.

The variable "public_ip_map" defined in terraform/*/output.tf files has also been changed to "ansible_ip_map" in order to abstract away the type of the IP address being used.

---

Please note that since I have only an OCI account, I haven't tested the changes on other cloud providers. However, the changes are limited to renaming "public_ip_map" to "ansible_ip_map" in terraform files.

 playbooks/roles/terraform/tasks/main.yml          |  8 ++++----
 playbooks/roles/terraform/templates/ssh_config.j2 |  4 ++--
 scripts/status_terraform.sh                       |  2 +-
 terraform/aws/output.tf                           |  2 +-
 terraform/azure/output.tf                         |  2 +-
 terraform/gce/output.tf                           |  2 +-
 terraform/oci/output.tf                           | 14 +++++++++-----
 terraform/openstack/output.tf                     |  2 +-
 8 files changed, 20 insertions(+), 16 deletions(-)
playbooks/roles/terraform/tasks/main.yml +4 -4
index d04dc997..d1c94264 100644
@@ -7,22 +7,22 @@
   tags:
     - bringup
 
-- name: Retrieve the public_ip_map from terraform
+- name: Retrieve the ansible_ip_map from terraform
   delegate_to: localhost
   run_once: true
   ansible.builtin.command:
     chdir: "{{ topdir_path }}/terraform/{{ kdevops_terraform_provider }}"
-    cmd: "terraform output -json public_ip_map"
+    cmd: "terraform output -json ansible_ip_map"
   register: terraform_output
   changed_when: false
   tags:
     - ssh
 
-- name: Convert the retrieved public_ip_map into a dictionary
+- name: Convert the retrieved ansible_ip_map into a dictionary
   delegate_to: localhost
   run_once: true
   ansible.builtin.set_fact:
-    public_ip_map: "{{ terraform_output.stdout | from_json }}"
+    ansible_ip_map: "{{ terraform_output.stdout | from_json }}"
   tags:
     - ssh
 
playbooks/roles/terraform/templates/ssh_config.j2 +2 -2
index d9b057b1..c6e62a61 100644
@@ -1,5 +1,5 @@
-Host {{ inventory_hostname }} {{ public_ip_map[inventory_hostname] }}
-	HostName {{ public_ip_map[inventory_hostname] }}
+Host {{ inventory_hostname }} {{ ansible_ip_map[inventory_hostname] }}
+	HostName {{ ansible_ip_map[inventory_hostname] }}
 	User {{ kdevops_terraform_ssh_config_user }}
 	Port 22
 	IdentityFile {{ kdevops_terraform_ssh_config_privkey_file }}
scripts/status_terraform.sh +1 -1
index dc82d79e..bc4ad309 100755
@@ -13,5 +13,5 @@ if [[ ${COUNT} -eq 1 ]]; then
 else
   echo "There are ${COUNT} active terraform resources on '$1'."
 fi
-terraform output public_ip_map
+terraform output ansible_ip_map
 exit 0
terraform/aws/output.tf +1 -1
index ab18bc55..b5e59eb1 100644
@@ -3,7 +3,7 @@
 # Each provider's output.tf needs to define a public_ip_map. This
 # map is used to build the Ansible controller's ssh configuration.
 # Each map entry contains the node's hostname and public IP address.
-output "public_ip_map" {
+output "ansible_ip_map" {
   description = "The public IP addresses assigned to each instance"
   value       = zipmap(var.kdevops_nodes[*], aws_eip.kdevops_eip[*].public_ip)
 }
terraform/azure/output.tf +1 -1
index 38104c90..deb7d141 100644
@@ -1,7 +1,7 @@
 # Each provider's output.tf needs to define a public_ip_map. This
 # map is used to build the Ansible controller's ssh configuration.
 # Each map entry contains the node's hostname and public IP address.
-output "public_ip_map" {
+output "ansible_ip_map" {
   description = "The public IP addresses assigned to each instance"
   value       = zipmap(var.kdevops_nodes[*], azurerm_public_ip.kdevops_publicip[*].ip_address)
 }
terraform/gce/output.tf +1 -1
index 15889cc4..9246216f 100644
@@ -3,7 +3,7 @@
 # Each provider's output.tf needs to define a public_ip_map. This
 # map is used to build the Ansible controller's ssh configuration.
 # Each map entry contains the node's hostname and public IP address.
-output "public_ip_map" {
+output "ansible_ip_map" {
   description = "The public IP addresses assigned to each instance"
   value = zipmap(var.kdevops_nodes[*],
   google_compute_instance.kdevops_instance[*].network_interface[0].access_config[0].nat_ip)
terraform/oci/output.tf +9 -5
index 1657b804..6562a1e8 100644
@@ -1,9 +1,13 @@
 # All generic output goes here
 
-# Each provider's output.tf needs to define a public_ip_map. This
+# Each provider's output.tf needs to define a ansible_ip_map. This
 # map is used to build the Ansible controller's ssh configuration.
-# Each map entry contains the node's hostname and public IP address.
-output "public_ip_map" {
-  description = "The public IP addresses assigned to each instance"
-  value       = zipmap(var.kdevops_nodes[*], oci_core_instance.kdevops_instance.*.public_ip)
+# Each map entry contains the node's hostname and public/private IP
+# address.
+output "ansible_ip_map" {
+  description = "The IP addresses assigned to each instance"
+  value       = zipmap(var.kdevops_nodes[*],
+    var.oci_assign_public_ip ?
+    oci_core_instance.kdevops_instance.*.public_ip :
+    oci_core_instance.kdevops_instance.*.private_ip)
 }
terraform/openstack/output.tf +1 -1
index d5d3a6b1..3dd139a3 100644
@@ -21,7 +21,7 @@ output "kdevops_hosts_and_ipv4" {
 # Each provider's output.tf needs to define a public_ip_map. This
 # map is used to build the Ansible controller's ssh configuration.
 # Each map entry contains the node's hostname and public IP address.
-output "public_ip_map" {
+output "ansible_ip_map" {
   description = "The public IP addresses assigned to each instance"
   value       = zipmap(var.kdevops_nodes[*], openstack_compute_instance_v2.kdevops_instances[*].access_ip_v4)
 }
Signature · 1 line
2.45.2
#4 lore raw

Re: [PATCH 3/3] Allow private IP address to be assigned to instances created on OCI

Quoted 124 lines · Chandan Babu R

The OCI tenancy available to kernel developers from Oracle allows only private IP addresses to be assigned to compute instances. Hence this commit brings back the ability to work with OCI instances having private IP addresses.

The variable "public_ip_map" defined in terraform/*/output.tf files has also been changed to "ansible_ip_map" in order to abstract away the type of the IP address being used.

---

Please note that since I have only an OCI account, I haven't tested the changes on other cloud providers. However, the changes are limited to renaming "public_ip_map" to "ansible_ip_map" in terraform files.

 playbooks/roles/terraform/tasks/main.yml          |  8 ++++----
 playbooks/roles/terraform/templates/ssh_config.j2 |  4 ++--
 scripts/status_terraform.sh                       |  2 +-
 terraform/aws/output.tf                           |  2 +-
 terraform/azure/output.tf                         |  2 +-
 terraform/gce/output.tf                           |  2 +-
 terraform/oci/output.tf                           | 14 +++++++++-----
 terraform/openstack/output.tf                     |  2 +-
 8 files changed, 20 insertions(+), 16 deletions(-)
playbooks/roles/terraform/tasks/main.yml +4 -4
index d04dc997..d1c94264 100644
@@ -7,22 +7,22 @@
   tags:
     - bringup
 
-- name: Retrieve the public_ip_map from terraform
+- name: Retrieve the ansible_ip_map from terraform
   delegate_to: localhost
   run_once: true
   ansible.builtin.command:
     chdir: "{{ topdir_path }}/terraform/{{ kdevops_terraform_provider }}"
-    cmd: "terraform output -json public_ip_map"
+    cmd: "terraform output -json ansible_ip_map"
   register: terraform_output
   changed_when: false
   tags:
     - ssh
 
-- name: Convert the retrieved public_ip_map into a dictionary
+- name: Convert the retrieved ansible_ip_map into a dictionary
   delegate_to: localhost
   run_once: true
   ansible.builtin.set_fact:
-    public_ip_map: "{{ terraform_output.stdout | from_json }}"
+    ansible_ip_map: "{{ terraform_output.stdout | from_json }}"
   tags:
     - ssh
 
playbooks/roles/terraform/templates/ssh_config.j2 +2 -2
index d9b057b1..c6e62a61 100644
@@ -1,5 +1,5 @@
-Host {{ inventory_hostname }} {{ public_ip_map[inventory_hostname] }}
-	HostName {{ public_ip_map[inventory_hostname] }}
+Host {{ inventory_hostname }} {{ ansible_ip_map[inventory_hostname] }}
+	HostName {{ ansible_ip_map[inventory_hostname] }}
 	User {{ kdevops_terraform_ssh_config_user }}
 	Port 22
 	IdentityFile {{ kdevops_terraform_ssh_config_privkey_file }}
scripts/status_terraform.sh +1 -1
index dc82d79e..bc4ad309 100755
@@ -13,5 +13,5 @@ if [[ ${COUNT} -eq 1 ]]; then
 else
   echo "There are ${COUNT} active terraform resources on '$1'."
 fi
-terraform output public_ip_map
+terraform output ansible_ip_map
 exit 0
terraform/aws/output.tf +1 -1
index ab18bc55..b5e59eb1 100644
@@ -3,7 +3,7 @@
 # Each provider's output.tf needs to define a public_ip_map. This
 # map is used to build the Ansible controller's ssh configuration.
 # Each map entry contains the node's hostname and public IP address.
-output "public_ip_map" {
+output "ansible_ip_map" {
   description = "The public IP addresses assigned to each instance"
   value       = zipmap(var.kdevops_nodes[*], aws_eip.kdevops_eip[*].public_ip)
 }
terraform/azure/output.tf +1 -1
index 38104c90..deb7d141 100644
@@ -1,7 +1,7 @@
 # Each provider's output.tf needs to define a public_ip_map. This
 # map is used to build the Ansible controller's ssh configuration.
 # Each map entry contains the node's hostname and public IP address.
-output "public_ip_map" {
+output "ansible_ip_map" {
   description = "The public IP addresses assigned to each instance"
   value       = zipmap(var.kdevops_nodes[*], azurerm_public_ip.kdevops_publicip[*].ip_address)
 }
terraform/gce/output.tf +1 -1
index 15889cc4..9246216f 100644
@@ -3,7 +3,7 @@
 # Each provider's output.tf needs to define a public_ip_map. This
 # map is used to build the Ansible controller's ssh configuration.
 # Each map entry contains the node's hostname and public IP address.
-output "public_ip_map" {
+output "ansible_ip_map" {
   description = "The public IP addresses assigned to each instance"
   value = zipmap(var.kdevops_nodes[*],
   google_compute_instance.kdevops_instance[*].network_interface[0].access_config[0].nat_ip)
terraform/oci/output.tf +0 -0
index 1657b804..6562a1e8 100644
@@ -1,9 +1,13 @@
 # All generic output goes here

terraform/oci/output.tf line 6

Quoted 10 lines
terraform/oci/output.tf +3 -5
 
-# Each provider's output.tf needs to define a public_ip_map. This
+# Each provider's output.tf needs to define a ansible_ip_map. This
 # map is used to build the Ansible controller's ssh configuration.
-# Each map entry contains the node's hostname and public IP address.
-output "public_ip_map" {
-  description = "The public IP addresses assigned to each instance"
-  value       = zipmap(var.kdevops_nodes[*], oci_core_instance.kdevops_instance.*.public_ip)
+# Each map entry contains the node's hostname and public/private IP
+# address.

Can you update the documenting comment in the output.tf file for the other providers as well?

terraform/oci/output.tf line 8

Quoted 2 lines
terraform/oci/output.tf +2 -0
+output "ansible_ip_map" {
+  description = "The IP addresses assigned to each instance"

Also, update the description for the ansible_ip_map output variable in all the output.tf files.

terraform/oci/output.tf line 12

Quoted 4 lines
terraform/oci/output.tf +4 -0
+  value       = zipmap(var.kdevops_nodes[*],
+    var.oci_assign_public_ip ?
+    oci_core_instance.kdevops_instance.*.public_ip :
+    oci_core_instance.kdevops_instance.*.private_ip)

Weird indentation. I assume this was the result of "terraform fmt" ?

Quoted 6 lines
terraform/oci/output.tf +0 -0
 }
terraform/openstack/output.tf +0 -0
index d5d3a6b1..3dd139a3 100644

terraform/openstack/output.tf output "kdevops_hosts_and_ipv4" { · line 27

Quoted 8 lines
terraform/openstack/output.tf +1 -1
@@ -21,7 +21,7 @@ output "kdevops_hosts_and_ipv4" {
 # Each provider's output.tf needs to define a public_ip_map. This
 # map is used to build the Ansible controller's ssh configuration.
 # Each map entry contains the node's hostname and public IP address.
-output "public_ip_map" {
+output "ansible_ip_map" {
   description = "The public IP addresses assigned to each instance"
   value       = zipmap(var.kdevops_nodes[*], openstack_compute_instance_v2.kdevops_instances[*].access_ip_v4)
 }

This patch makes sense to me, just needs a little polish.

Signature · 1 line
Chuck Lever
#5 lore raw

Re: [PATCH 3/3] Allow private IP address to be assigned to instances created on OCI

Quoted 8 lines · Chuck Lever
Quoted 7 lines · Chandan Babu R

The OCI tenancy available to kernel developers from Oracle allows only private IP addresses to be assigned to compute instances. Hence this commit brings back the ability to work with OCI instances having private IP addresses.

The variable "public_ip_map" defined in terraform/*/output.tf files has also been changed to "ansible_ip_map" in order to abstract away the type of the IP address being used.

Duh. I know I suggested the name, but "ansible_ip_map" might suggest that Ansible defines this variable, like all other variables named ansible_something.

Other possibilities:

ips_for_ansible
controller_ip_map

Quoted 164 lines
Quoted 116 lines

---

Please note that since I have only an OCI account, I haven't tested the changes on other cloud providers. However, the changes are limited to renaming "public_ip_map" to "ansible_ip_map" in terraform files.

 playbooks/roles/terraform/tasks/main.yml          |  8 ++++----
 playbooks/roles/terraform/templates/ssh_config.j2 |  4 ++--
 scripts/status_terraform.sh                       |  2 +-
 terraform/aws/output.tf                           |  2 +-
 terraform/azure/output.tf                         |  2 +-
 terraform/gce/output.tf                           |  2 +-
 terraform/oci/output.tf                           | 14 +++++++++-----
 terraform/openstack/output.tf                     |  2 +-
 8 files changed, 20 insertions(+), 16 deletions(-)
playbooks/roles/terraform/tasks/main.yml +4 -4
index d04dc997..d1c94264 100644
@@ -7,22 +7,22 @@
   tags:
     - bringup
 
-- name: Retrieve the public_ip_map from terraform
+- name: Retrieve the ansible_ip_map from terraform
   delegate_to: localhost
   run_once: true
   ansible.builtin.command:
     chdir: "{{ topdir_path }}/terraform/{{ kdevops_terraform_provider }}"
-    cmd: "terraform output -json public_ip_map"
+    cmd: "terraform output -json ansible_ip_map"
   register: terraform_output
   changed_when: false
   tags:
     - ssh
 
-- name: Convert the retrieved public_ip_map into a dictionary
+- name: Convert the retrieved ansible_ip_map into a dictionary
   delegate_to: localhost
   run_once: true
   ansible.builtin.set_fact:
-    public_ip_map: "{{ terraform_output.stdout | from_json }}"
+    ansible_ip_map: "{{ terraform_output.stdout | from_json }}"
   tags:
     - ssh
 
playbooks/roles/terraform/templates/ssh_config.j2 +2 -2
index d9b057b1..c6e62a61 100644
@@ -1,5 +1,5 @@
-Host {{ inventory_hostname }} {{ public_ip_map[inventory_hostname] }}
-	HostName {{ public_ip_map[inventory_hostname] }}
+Host {{ inventory_hostname }} {{ ansible_ip_map[inventory_hostname] }}
+	HostName {{ ansible_ip_map[inventory_hostname] }}
 	User {{ kdevops_terraform_ssh_config_user }}
 	Port 22
 	IdentityFile {{ kdevops_terraform_ssh_config_privkey_file }}
scripts/status_terraform.sh +1 -1
index dc82d79e..bc4ad309 100755
@@ -13,5 +13,5 @@ if [[ ${COUNT} -eq 1 ]]; then
 else
   echo "There are ${COUNT} active terraform resources on '$1'."
 fi
-terraform output public_ip_map
+terraform output ansible_ip_map
 exit 0
terraform/aws/output.tf +1 -1
index ab18bc55..b5e59eb1 100644
@@ -3,7 +3,7 @@
 # Each provider's output.tf needs to define a public_ip_map. This
 # map is used to build the Ansible controller's ssh configuration.
 # Each map entry contains the node's hostname and public IP address.
-output "public_ip_map" {
+output "ansible_ip_map" {
   description = "The public IP addresses assigned to each instance"
   value       = zipmap(var.kdevops_nodes[*], aws_eip.kdevops_eip[*].public_ip)
 }
terraform/azure/output.tf +1 -1
index 38104c90..deb7d141 100644
@@ -1,7 +1,7 @@
 # Each provider's output.tf needs to define a public_ip_map. This
 # map is used to build the Ansible controller's ssh configuration.
 # Each map entry contains the node's hostname and public IP address.
-output "public_ip_map" {
+output "ansible_ip_map" {
   description = "The public IP addresses assigned to each instance"
   value       = zipmap(var.kdevops_nodes[*], azurerm_public_ip.kdevops_publicip[*].ip_address)
 }
terraform/gce/output.tf +1 -1
index 15889cc4..9246216f 100644
@@ -3,7 +3,7 @@
 # Each provider's output.tf needs to define a public_ip_map. This
 # map is used to build the Ansible controller's ssh configuration.
 # Each map entry contains the node's hostname and public IP address.
-output "public_ip_map" {
+output "ansible_ip_map" {
   description = "The public IP addresses assigned to each instance"
   value = zipmap(var.kdevops_nodes[*],
   google_compute_instance.kdevops_instance[*].network_interface[0].access_config[0].nat_ip)
terraform/oci/output.tf +0 -0
index 1657b804..6562a1e8 100644
@@ -1,9 +1,13 @@
 # All generic output goes here

terraform/oci/output.tf line 6

Quoted 10 lines
terraform/oci/output.tf +3 -5
 
-# Each provider's output.tf needs to define a public_ip_map. This
+# Each provider's output.tf needs to define a ansible_ip_map. This
 # map is used to build the Ansible controller's ssh configuration.
-# Each map entry contains the node's hostname and public IP address.
-output "public_ip_map" {
-  description = "The public IP addresses assigned to each instance"
-  value       = zipmap(var.kdevops_nodes[*], oci_core_instance.kdevops_instance.*.public_ip)
+# Each map entry contains the node's hostname and public/private IP
+# address.

Can you update the documenting comment in the output.tf file for the other providers as well?

terraform/oci/output.tf line 8

Quoted 2 lines
terraform/oci/output.tf +2 -0
+output "ansible_ip_map" {
+  description = "The IP addresses assigned to each instance"

Also, update the description for the ansible_ip_map output variable in all the output.tf files.

terraform/oci/output.tf line 12

Quoted 4 lines
terraform/oci/output.tf +4 -0
+  value       = zipmap(var.kdevops_nodes[*],
+    var.oci_assign_public_ip ?
+    oci_core_instance.kdevops_instance.*.public_ip :
+    oci_core_instance.kdevops_instance.*.private_ip)

Weird indentation. I assume this was the result of "terraform fmt" ?

Quoted 6 lines
terraform/oci/output.tf +0 -0
 }
terraform/openstack/output.tf +0 -0
index d5d3a6b1..3dd139a3 100644

terraform/openstack/output.tf output "kdevops_hosts_and_ipv4" { · line 27

Quoted 8 lines
terraform/openstack/output.tf +1 -1
@@ -21,7 +21,7 @@ output "kdevops_hosts_and_ipv4" {
 # Each provider's output.tf needs to define a public_ip_map. This
 # map is used to build the Ansible controller's ssh configuration.
 # Each map entry contains the node's hostname and public IP address.
-output "public_ip_map" {
+output "ansible_ip_map" {
   description = "The public IP addresses assigned to each instance"
   value       = zipmap(var.kdevops_nodes[*], openstack_compute_instance_v2.kdevops_instances[*].access_ip_v4)
 }

This patch makes sense to me, just needs a little polish.

Signature · 1 line
Chuck Lever
#6 lore raw

Re: [PATCH 3/3] Allow private IP address to be assigned to instances created on OCI

Quoted 10 lines · Chuck Lever
Quoted 8 lines · Chuck Lever
Quoted 7 lines · Chandan Babu R

The OCI tenancy available to kernel developers from Oracle allows only private IP addresses to be assigned to compute instances. Hence this commit brings back the ability to work with OCI instances having private IP addresses.

The variable "public_ip_map" defined in terraform/*/output.tf files has also been changed to "ansible_ip_map" in order to abstract away the type of the IP address being used.

Quoted 9 lines

Duh. I know I suggested the name, but "ansible_ip_map" might suggest that Ansible defines this variable, like all other variables named ansible_something.

Other possibilities:

ips_for_ansible
controller_ip_map

I think controller_ip_map is a better name. I will use that.

Quoted 119 lines
Quoted 119 lines
Quoted 119 lines

---

Please note that since I have only an OCI account, I haven't tested the changes on other cloud providers. However, the changes are limited to renaming "public_ip_map" to "ansible_ip_map" in terraform files.

 playbooks/roles/terraform/tasks/main.yml          |  8 ++++----
 playbooks/roles/terraform/templates/ssh_config.j2 |  4 ++--
 scripts/status_terraform.sh                       |  2 +-
 terraform/aws/output.tf                           |  2 +-
 terraform/azure/output.tf                         |  2 +-
 terraform/gce/output.tf                           |  2 +-
 terraform/oci/output.tf                           | 14 +++++++++-----
 terraform/openstack/output.tf                     |  2 +-
 8 files changed, 20 insertions(+), 16 deletions(-)
playbooks/roles/terraform/tasks/main.yml +4 -4
index d04dc997..d1c94264 100644
@@ -7,22 +7,22 @@
   tags:
     - bringup
 
-- name: Retrieve the public_ip_map from terraform
+- name: Retrieve the ansible_ip_map from terraform
   delegate_to: localhost
   run_once: true
   ansible.builtin.command:
     chdir: "{{ topdir_path }}/terraform/{{ kdevops_terraform_provider }}"
-    cmd: "terraform output -json public_ip_map"
+    cmd: "terraform output -json ansible_ip_map"
   register: terraform_output
   changed_when: false
   tags:
     - ssh
 
-- name: Convert the retrieved public_ip_map into a dictionary
+- name: Convert the retrieved ansible_ip_map into a dictionary
   delegate_to: localhost
   run_once: true
   ansible.builtin.set_fact:
-    public_ip_map: "{{ terraform_output.stdout | from_json }}"
+    ansible_ip_map: "{{ terraform_output.stdout | from_json }}"
   tags:
     - ssh
 
playbooks/roles/terraform/templates/ssh_config.j2 +2 -2
index d9b057b1..c6e62a61 100644
@@ -1,5 +1,5 @@
-Host {{ inventory_hostname }} {{ public_ip_map[inventory_hostname] }}
-	HostName {{ public_ip_map[inventory_hostname] }}
+Host {{ inventory_hostname }} {{ ansible_ip_map[inventory_hostname] }}
+	HostName {{ ansible_ip_map[inventory_hostname] }}
 	User {{ kdevops_terraform_ssh_config_user }}
 	Port 22
 	IdentityFile {{ kdevops_terraform_ssh_config_privkey_file }}
scripts/status_terraform.sh +1 -1
index dc82d79e..bc4ad309 100755
@@ -13,5 +13,5 @@ if [[ ${COUNT} -eq 1 ]]; then
 else
   echo "There are ${COUNT} active terraform resources on '$1'."
 fi
-terraform output public_ip_map
+terraform output ansible_ip_map
 exit 0
terraform/aws/output.tf +1 -1
index ab18bc55..b5e59eb1 100644
@@ -3,7 +3,7 @@
 # Each provider's output.tf needs to define a public_ip_map. This
 # map is used to build the Ansible controller's ssh configuration.
 # Each map entry contains the node's hostname and public IP address.
-output "public_ip_map" {
+output "ansible_ip_map" {
   description = "The public IP addresses assigned to each instance"
   value       = zipmap(var.kdevops_nodes[*], aws_eip.kdevops_eip[*].public_ip)
 }
terraform/azure/output.tf +1 -1
index 38104c90..deb7d141 100644
@@ -1,7 +1,7 @@
 # Each provider's output.tf needs to define a public_ip_map. This
 # map is used to build the Ansible controller's ssh configuration.
 # Each map entry contains the node's hostname and public IP address.
-output "public_ip_map" {
+output "ansible_ip_map" {
   description = "The public IP addresses assigned to each instance"
   value       = zipmap(var.kdevops_nodes[*], azurerm_public_ip.kdevops_publicip[*].ip_address)
 }
terraform/gce/output.tf +1 -1
index 15889cc4..9246216f 100644
@@ -3,7 +3,7 @@
 # Each provider's output.tf needs to define a public_ip_map. This
 # map is used to build the Ansible controller's ssh configuration.
 # Each map entry contains the node's hostname and public IP address.
-output "public_ip_map" {
+output "ansible_ip_map" {
   description = "The public IP addresses assigned to each instance"
   value = zipmap(var.kdevops_nodes[*],
   google_compute_instance.kdevops_instance[*].network_interface[0].access_config[0].nat_ip)
terraform/oci/output.tf +0 -0
index 1657b804..6562a1e8 100644
@@ -1,9 +1,13 @@
 # All generic output goes here
 
Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
terraform/oci/output.tf +1 -2
-# Each provider's output.tf needs to define a public_ip_map. This
+# Each provider's output.tf needs to define a ansible_ip_map. This
 # map is used to build the Ansible controller's ssh configuration.
-# Each map entry contains the node's hostname and public IP address.
Quoted 10 lines

terraform/oci/output.tf line 6

Quoted 5 lines
terraform/oci/output.tf +2 -3
-output "public_ip_map" {
-  description = "The public IP addresses assigned to each instance"
-  value       = zipmap(var.kdevops_nodes[*], oci_core_instance.kdevops_instance.*.public_ip)
+# Each map entry contains the node's hostname and public/private IP
+# address.

Can you update the documenting comment in the output.tf file for the other providers as well?

Ok.

Quoted 6 lines
Quoted 6 lines

terraform/oci/output.tf line 8

Quoted 2 lines
terraform/oci/output.tf +2 -0
+output "ansible_ip_map" {
+  description = "The IP addresses assigned to each instance"

Also, update the description for the ansible_ip_map output variable in all the output.tf files.

Sure, I will do that.

Quoted 7 lines
Quoted 7 lines

terraform/oci/output.tf line 12

Quoted 5 lines
terraform/oci/output.tf +4 -0
+  value       = zipmap(var.kdevops_nodes[*],
+    var.oci_assign_public_ip ?
+    oci_core_instance.kdevops_instance.*.public_ip :
+    oci_core_instance.kdevops_instance.*.private_ip)

Weird indentation. I assume this was the result of "terraform fmt" ?

Sorry, I had used my text editor's default indentation. I will fix it.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
terraform/oci/output.tf +0 -0
 }
terraform/openstack/output.tf +0 -0
index d5d3a6b1..3dd139a3 100644
@@ -21,7 +21,7 @@ output "kdevops_hosts_and_ipv4" {
 # Each provider's output.tf needs to define a public_ip_map. This
 # map is used to build the Ansible controller's ssh configuration.
 # Each map entry contains the node's hostname and public IP address.
Quoted 8 lines
Quoted 8 lines

terraform/openstack/output.tf output "kdevops_hosts_and_ipv4" { · line 27

Quoted 5 lines
terraform/openstack/output.tf +1 -1
-output "public_ip_map" {
+output "ansible_ip_map" {
   description = "The public IP addresses assigned to each instance"
   value       = zipmap(var.kdevops_nodes[*], openstack_compute_instance_v2.kdevops_instances[*].access_ip_v4)
 }

This patch makes sense to me, just needs a little polish.

Thanks for reviewing all the patches.

I will make the required modifications and post V2 soon.

Signature · 1 line
Chandan
#7 lore raw
In reply to Chandan Babu R
Quoted 18 lines · Chandan Babu R

kdevops_terraform_ssh_config_privkey_file is not set on control systems which use pre-existing ssh keys. Hence, adding entries of provisioned cloud instances to the ephemeral ssh config file fails on such systems.

Fix this by setting kdevops_terraform_ssh_config_privkey_file unconditionally.

---
 scripts/terraform.Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/terraform.Makefile +0 -0
index 91469469..b6b26e69 100644
@@ -85,10 +85,10 @@ endif # CONFIG_KDEVOPS_SSH_CONFIG_UPDATE
 export KDEVOPS_SSH_PUBKEY:=$(shell realpath $(subst ",,$(CONFIG_TERRAFORM_SSH_CONFIG_PUBKEY_FILE)))

scripts/terraform.Makefile endif # CONFIG_KDEVOPS_SSH_CONFIG_UPDATE · line 94

Quoted 10 lines
scripts/terraform.Makefile +1 -1
 TERRAFORM_EXTRA_VARS += kdevops_terraform_ssh_config_pubkey_file='$(KDEVOPS_SSH_PUBKEY)'
 TERRAFORM_EXTRA_VARS += kdevops_terraform_ssh_config_user='$(SSH_CONFIG_USER)'
+TERRAFORM_EXTRA_VARS += kdevops_terraform_ssh_config_privkey_file='$(basename $(KDEVOPS_SSH_PUBKEY))'
 
 ifeq (y,$(CONFIG_TERRAFORM_SSH_CONFIG_GENKEY))
 export KDEVOPS_SSH_PRIVKEY:=$(basename $(KDEVOPS_SSH_PUBKEY))
-TERRAFORM_EXTRA_VARS += kdevops_terraform_ssh_config_privkey_file='$(KDEVOPS_SSH_PRIVKEY)'
 
 ifeq (y,$(CONFIG_TERRAFORM_SSH_CONFIG_GENKEY_OVERWRITE))
 DEFAULT_DEPS += remove-ssh-key

I need to think about this one / test it. Might have side effects, but maybe not.

Signature · 1 line
Chuck Lever
Reviewed-by
#8 lore raw
Quoted 27 lines · Chuck Lever
Quoted 26 lines · Chandan Babu R

kdevops_terraform_ssh_config_privkey_file is not set on control systems which use pre-existing ssh keys. Hence, adding entries of provisioned cloud instances to the ephemeral ssh config file fails on such systems.

Fix this by setting kdevops_terraform_ssh_config_privkey_file unconditionally.

---
 scripts/terraform.Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/terraform.Makefile +1 -1
index 91469469..b6b26e69 100644
@@ -85,10 +85,10 @@ endif # CONFIG_KDEVOPS_SSH_CONFIG_UPDATE
 export KDEVOPS_SSH_PUBKEY:=$(shell realpath $(subst ",,$(CONFIG_TERRAFORM_SSH_CONFIG_PUBKEY_FILE)))
 TERRAFORM_EXTRA_VARS += kdevops_terraform_ssh_config_pubkey_file='$(KDEVOPS_SSH_PUBKEY)'
 TERRAFORM_EXTRA_VARS += kdevops_terraform_ssh_config_user='$(SSH_CONFIG_USER)'
+TERRAFORM_EXTRA_VARS += kdevops_terraform_ssh_config_privkey_file='$(basename $(KDEVOPS_SSH_PUBKEY))'
 
 ifeq (y,$(CONFIG_TERRAFORM_SSH_CONFIG_GENKEY))
 export KDEVOPS_SSH_PRIVKEY:=$(basename $(KDEVOPS_SSH_PUBKEY))
-TERRAFORM_EXTRA_VARS += kdevops_terraform_ssh_config_privkey_file='$(KDEVOPS_SSH_PRIVKEY)'
 
Quoted 7 lines

scripts/terraform.Makefile endif # CONFIG_KDEVOPS_SSH_CONFIG_UPDATE · line 94

Quoted 2 lines
scripts/terraform.Makefile +0 -0
 ifeq (y,$(CONFIG_TERRAFORM_SSH_CONFIG_GENKEY_OVERWRITE))
 DEFAULT_DEPS += remove-ssh-key

I need to think about this one / test it. Might have side effects, but maybe not.

and confirmed it's doesn't seem to break anything in a simple smoke test on Azure.

Signature · 1 line
Chuck Lever