diff --git a/.gitignore b/.gitignore index 07b7bdf..9e6d821 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.tfvars *.tfstate.backup .terraform* +playbooks diff --git a/README.md b/README.md index 68f8620..81acd36 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ Put your vars inside a terraform.tfvars such as : ``` ansible_hostname = "blabla.domain.tld" ansible_playbook_path = "/path/to/playbook.yml" +ansible_key_file = "/home/user/ssh/my_key" +ansible_ssh_user = "ssh-username" ``` Then run : diff --git a/main.tf b/main.tf index 49ca282..637690a 100644 --- a/main.tf +++ b/main.tf @@ -15,6 +15,10 @@ resource "ansible_host" "host" { resource "ansible_group" "group" { name = "thegroup" children = [var.ansible_hostname] + variables = { + ansible_ssh_user = var.ansible_ssh_user + ansible_ssh_private_key_file = var.ansible_key_file + } } resource "ansible_playbook" "playbook" { diff --git a/outputs.tf b/outputs.tf index e69de29..54feda7 100644 --- a/outputs.tf +++ b/outputs.tf @@ -0,0 +1,14 @@ +output "playbook_return" { + description = "stdout of the playbook" + value = ansible_playbook.playbook.ansible_playbook_stdout +} + +output "playbook_path" { + description = "path of the playbook" + value = ansible_playbook.playbook.playbook +} + +output "host_address" { + description = "IP address or hostname used to connect to the host." + value = "ansible_host.host.name" +} diff --git a/variables.tf b/variables.tf index 8c9a562..a7358a5 100644 --- a/variables.tf +++ b/variables.tf @@ -7,3 +7,14 @@ variable "ansible_playbook_path" { description = "Path of the playbook to run" type = string } + +variable "ansible_ssh_user" { + description = "User to connect as in ssh" + type = string + default = "root" +} + +variable "ansible_key_file" { + description = "Private key to use for connection" + type = string +}