Added outputs
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@
|
|||||||
*.tfvars
|
*.tfvars
|
||||||
*.tfstate.backup
|
*.tfstate.backup
|
||||||
.terraform*
|
.terraform*
|
||||||
|
playbooks
|
||||||
|
|||||||
@ -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 :
|
||||||
|
|||||||
4
main.tf
4
main.tf
@ -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" {
|
||||||
|
|||||||
14
outputs.tf
14
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"
|
||||||
|
}
|
||||||
|
|||||||
11
variables.tf
11
variables.tf
@ -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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user