feat: add user and ssh key to ansible inventory

This commit is contained in:
Ditmar Visser
2025-05-28 12:18:25 +00:00
parent 9b0409c170
commit 0a1505259f
3 changed files with 12 additions and 3 deletions

View File

@ -1,2 +1,2 @@
[all] [all]
vm ansible_host=${ip} vm ansible_host=${ip} ansible_user=${user} ansible_ssh_private_key_file=${private_key_file}

View File

@ -69,6 +69,7 @@ data "template_file" "azure_cloudinit" {
template = file("${path.module}/cloudinit-azure.yaml") template = file("${path.module}/cloudinit-azure.yaml")
vars = { vars = {
azure-ssh-key = trimspace(data.azurerm_ssh_public_key.azure.public_key) azure-ssh-key = trimspace(data.azurerm_ssh_public_key.azure.public_key)
azure-user = trimspace(var.azure_user)
} }
} }
@ -104,12 +105,15 @@ resource "azurerm_linux_virtual_machine" "main" {
locals { locals {
inventory_content = templatefile("${path.module}/ansible-inventory.tmpl", { inventory_content = templatefile("${path.module}/ansible-inventory.tmpl", {
ip = azurerm_linux_virtual_machine.main.public_ip_address }) ip = azurerm_linux_virtual_machine.main.public_ip_address,
user = var.azure_user,
private_key_file = var.azure_private_key_path
})
} }
resource "local_file" "ansible_inventory" { resource "local_file" "ansible_inventory" {
content = local.inventory_content content = local.inventory_content
filename = "${path.module}/inventory.ini" filename = "${path.module}/../opdracht-2/inventory.ini"
} }

View File

@ -35,6 +35,11 @@ variable "azure_location" {
default = "westeurope" default = "westeurope"
} }
variable "azure_user" {
description = "User that will gain access to the Azure vm's"
default = "iac"
}
variable "prefix" { variable "prefix" {
description = "The Prefix used for all resources" description = "The Prefix used for all resources"
default = "week-3-opdracht-1" default = "week-3-opdracht-1"