Added outputs

This commit is contained in:
Justine Pelletreau
2026-02-23 18:29:16 +01:00
parent 27bbe4b275
commit bbaddef217
5 changed files with 32 additions and 0 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
*.tfvars *.tfvars
*.tfstate.backup *.tfstate.backup
.terraform* .terraform*
playbooks

View File

@ -7,6 +7,8 @@ Put your vars inside a terraform.tfvars such as :
``` ```
ansible_hostname = "blabla.domain.tld" ansible_hostname = "blabla.domain.tld"
ansible_playbook_path = "/path/to/playbook.yml" ansible_playbook_path = "/path/to/playbook.yml"
ansible_key_file = "/home/user/ssh/my_key"
ansible_ssh_user = "ssh-username"
``` ```
Then run : Then run :

View File

@ -15,6 +15,10 @@ resource "ansible_host" "host" {
resource "ansible_group" "group" { resource "ansible_group" "group" {
name = "thegroup" name = "thegroup"
children = [var.ansible_hostname] 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" { resource "ansible_playbook" "playbook" {

View File

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

View File

@ -7,3 +7,14 @@ variable "ansible_playbook_path" {
description = "Path of the playbook to run" description = "Path of the playbook to run"
type = string 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
}