feat: write to ansible hosts
This commit is contained in:
parent
0919a9b40c
commit
ec721711ca
8
sandbox/terraform/libvirt/ubuntu/templates/hosts.yml.tpl
Normal file
8
sandbox/terraform/libvirt/ubuntu/templates/hosts.yml.tpl
Normal file
|
@ -0,0 +1,8 @@
|
|||
live:
|
||||
hosts:
|
||||
ubuntu:
|
||||
ansible_host: ${ubuntu_ip}
|
||||
ansible_user: atm
|
||||
debian:
|
||||
ansible_host: ${debian_ip}
|
||||
ansible_user: atm
|
|
@ -1,5 +1,5 @@
|
|||
terraform {
|
||||
required_version = ">= 0.13"
|
||||
required_version = ">= 0.13"
|
||||
required_providers {
|
||||
libvirt = {
|
||||
source = "dmacvicar/libvirt"
|
||||
|
@ -65,7 +65,7 @@ resource "libvirt_domain" "domain-ubuntu" {
|
|||
cloudinit = libvirt_cloudinit_disk.commoninit.id
|
||||
|
||||
network_interface {
|
||||
network_name = "default"
|
||||
network_name = "default"
|
||||
wait_for_lease = true
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ resource "libvirt_domain" "domain-debian-ansible-playground" {
|
|||
cloudinit = libvirt_cloudinit_disk.commoninit.id
|
||||
|
||||
network_interface {
|
||||
network_name = "default"
|
||||
network_name = "default"
|
||||
wait_for_lease = true
|
||||
}
|
||||
|
||||
|
@ -145,3 +145,13 @@ output "ubuntu_ip" {
|
|||
output "debian_ip" {
|
||||
value = length(libvirt_domain.domain-debian-ansible-playground.network_interface[0].addresses) > 0 ? libvirt_domain.domain-debian-ansible-playground.network_interface[0].addresses[0] : ""
|
||||
}
|
||||
|
||||
resource "local_file" "hosts_yml" {
|
||||
content = templatefile("./templates/hosts.yml.tpl",
|
||||
{
|
||||
debian_ip = "${length(libvirt_domain.domain-debian-ansible-playground.network_interface[0].addresses) > 0 ? libvirt_domain.domain-debian-ansible-playground.network_interface[0].addresses[0] : ""}"
|
||||
ubuntu_ip = "${length(libvirt_domain.domain-ubuntu.network_interface[0].addresses) > 0 ? libvirt_domain.domain-ubuntu.network_interface[0].addresses[0] : ""}"
|
||||
})
|
||||
|
||||
filename = "./ansible/inventory/hosts.yml"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue