mirror of
https://github.com/khuedoan/homelab.git
synced 2025-01-07 14:03:01 +07:00
Add Ansible provisioner module
This commit is contained in:
parent
c1a993cd22
commit
a6a1a7266d
13
infra/modules/ansible-provisioner/main.tf
Normal file
13
infra/modules/ansible-provisioner/main.tf
Normal file
@ -0,0 +1,13 @@
|
||||
resource "null_resource" "ansible_provisioner" {
|
||||
triggers = {
|
||||
ansible_hash = md5(join("", [for files in fileset("${var.ansible_directory}/", "**") : file("${var.ansible_directory}/${files}")]))
|
||||
}
|
||||
|
||||
provisioner "local-exec" {
|
||||
command = "ansible-playbook --user ${var.ansible_user} --inventory ${join(",", var.ansible_inventory)}, --private-key ${var.ansible_private_key} ${path.ansible_directory}/${var.ansible_playbook}"
|
||||
|
||||
environment = {
|
||||
ANSIBLE_HOST_KEY_CHECKING = "False"
|
||||
}
|
||||
}
|
||||
}
|
26
infra/modules/ansible-provisioner/variables.tf
Normal file
26
infra/modules/ansible-provisioner/variables.tf
Normal file
@ -0,0 +1,26 @@
|
||||
var "ansible_directory" {
|
||||
description = "Path to Ansible directory"
|
||||
type = string
|
||||
}
|
||||
|
||||
var "ansible_playbook" {
|
||||
description = "Path to Ansible playbook, relative to Ansible directory"
|
||||
type = string
|
||||
default = "main.yml"
|
||||
}
|
||||
|
||||
var "ansible_user" {
|
||||
description = "User to connect as"
|
||||
type = string
|
||||
default = "ubuntu"
|
||||
}
|
||||
|
||||
var "ansible_inventory" {
|
||||
description = "List of hosts for Ansible to run against"
|
||||
type = list(string)
|
||||
}
|
||||
|
||||
var "ansible_private_key" {
|
||||
description = "Private key file to authenticate the connection"
|
||||
type = list(string)
|
||||
}
|
Loading…
Reference in New Issue
Block a user