aboutsummaryrefslogtreecommitdiff
path: root/opentofu/modules/ansible_provisioner/main.tf
diff options
context:
space:
mode:
authorclyhtsuriva <aimeric@adjutor.xyz>2025-02-03 17:21:58 +0100
committerclyhtsuriva <aimeric@adjutor.xyz>2025-02-03 17:21:58 +0100
commit4e2703c52026009c34e8dcb8294b50881f9152f8 (patch)
treec125c5405bfadb2eb802b2b3c12486274815b293 /opentofu/modules/ansible_provisioner/main.tf
parent6135497b6b4837cb8bd65bc093b48ef6a14fbf7d (diff)
opentofu: add kubespray submodule to deploy via ansible
Not working yet, getting : "msg": "Ansible must be between 2.16.4 and 2.17.0 exclusive - you have 2.17.5"
Diffstat (limited to 'opentofu/modules/ansible_provisioner/main.tf')
-rw-r--r--opentofu/modules/ansible_provisioner/main.tf27
1 files changed, 27 insertions, 0 deletions
diff --git a/opentofu/modules/ansible_provisioner/main.tf b/opentofu/modules/ansible_provisioner/main.tf
new file mode 100644
index 0000000..54e3346
--- /dev/null
+++ b/opentofu/modules/ansible_provisioner/main.tf
@@ -0,0 +1,27 @@
+variable "vm_ip" {
+ default = null
+}
+
+variable "inventory_file_path" {
+ default = null
+}
+
+variable "vm_username" {}
+variable "ssh_private_key_path" {}
+variable "ansible_playbook_path" {}
+
+resource "null_resource" "ansible_provisioner" {
+ triggers = {
+ ip_or_inventory = coalesce(var.vm_ip, var.inventory_file_path) # Choose based on what is provided
+ }
+
+ provisioner "local-exec" {
+ command = <<-EOT
+ ANSIBLE_HOST_KEY_CHECKING=False ANSIBLE_CONFIG=${path.root}/../ansible/ansible.cfg ansible-playbook \
+ -i ${var.inventory_file_path != null ? var.inventory_file_path : "${var.vm_ip},"} \
+ -u ${var.vm_username} \
+ --private-key ${var.ssh_private_key_path} \
+ ${var.ansible_playbook_path}
+ EOT
+ }
+}