【发布时间】:2021-03-26 23:36:27
【问题描述】:
我尝试将我的 coturn 服务器的所有浮动 ips 放入 ansible 库存中。
resource "local_file" "hosts_cfg" {
content = templatefile("${path.module}/templates/hosts.tpl",
{
coturn = openstack_compute_floatingip_associate_v2.coturn[*].floating_ip
}
)
filename = "../ansible/inventory/hosts.cfg"
}
错误:该对象没有名为“floating_ip”的属性。
resource "local_file" "hosts_cfg" {
content = templatefile("${path.module}/templates/hosts.tpl",
{
coturn = openstack_compute_floatingip_associate_v2.coturn["coturn-1"].floating_ip
}
)
filename = "../ansible/inventory/hosts.cfg"
}
有效,但仅适用于一个实例。
我的模板文件。
[coturn]
%{ for ip in coturn ~}
${ip}
%{ endfor ~}
我的 openstack_compute_floatingip_associate_v2 定义。
resource "openstack_compute_floatingip_associate_v2" "coturn" {
for_each = var.coturn_instance_names
floating_ip = openstack_networking_floatingip_v2.coturn[each.key].address
instance_id = openstack_compute_instance_v2.coturn[each.key].id
}
【问题讨论】:
-
你对
openstack_compute_floatingip_associate_v2的定义是什么? -
您可以通过设置
coturn = openstack_compute_floatingip_associate_v2.coturn然后在模板中循环遍历地图并为每个值访问floating_ip来解决问题。
标签: ansible terraform openstack ansible-inventory terraform-provider-openstack