Инвентори файл для ansible
Создал tf файл в терраформ '
resource "local_file" "hosts_cfg" {
content = templatefile("${path.module}/hosts.tftpl", {
webservers = yandex_compute_instance.web,
database = yandex_compute_instance.database,
storage = yandex_compute_instance.storage
})
filename = "${path.module}/hosts.cfg"
}'
Шаблон
'[webservers]
%{~ for i in webservers ~}
${i["name"]} ansible_host=${i["network_interface"][0]["nat_ip_address"]}
%{~ endfor ~}
[database]
%{~ for i in database ~}
${i["name"]} ansible_host=${i["network_interface"][0]["nat_ip_address"]}
%{~ endfor ~}
[storage]
%{~ for i in storage ~}
${i["name"]} ansible_host=${i["network_interface"][0]["nat_ip_address"]}
%{~ endfor ~}'
Выходит ошибка что не верно. Помогите понять как задать верный шаблон, или я не правильно передаю переменные? В итоге после запуска нужен инвентори файл с адресами для трех групп.
Источник: Stack Overflow на русском