Add Ansible provisioner module

This commit is contained in:
Khue Doan 2021-05-02 21:58:33 +07:00
parent c1a993cd22
commit a6a1a7266d
2 changed files with 39 additions and 0 deletions

View 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"
}
}
}

View 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)
}