【问题标题】:Error when trying to print ip to a file using terraform local-exec尝试使用 terraform local-exec 将 ip 打印到文件时出错
【发布时间】:2017-10-07 01:05:36
【问题描述】:

我正在尝试将新创建的实例的私有 ip 打印到本地运行 terraform 的主机文件中,以将其用于 ansible,但是每次我在本地修改我的转义字符时,terraform 都会抛出错误-执行回显命令。

这是我遇到错误的 sn-p:

 provisioner "local-exec"
{
command = " echo \"[servers]\["${aws_instance.seeds.*.private_ip}"\]\" >> /ec2-ansible/hosts"
}

hosts 文件中的预期输出:

[servers]
ip1
ip2
ip3

我遇到的错误:

未能加载根配置模块:解析 /root/ec2-ansible/main.tf 时出错:在 33:1:预期:IDENT |字符串 |分配 | LBRACE 得到:RBRACE
无法加载根配置模块:解析/root/ec2-ansible/main.tf时出错:29:25:非法字符

请帮帮我。

【问题讨论】:

  • [servers] 之后,[ 上有一个反斜杠转义符,但后面的引号中没有。

标签: amazon-web-services ansible devops terraform


【解决方案1】:

我认为你在使用 terraform 和 ansible 时走错了方向。

在ansible中,你可以使用Dynamic Inventory从标签、大小、ami id等中轻松获取主机信息,例如私有IP。

在 terraform 中,如果您需要 state 详细信息和 feed 到 ansible,建议使用terraform output 收集信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-07
    • 2019-09-30
    • 2016-09-04
    • 2018-09-03
    • 2021-09-03
    • 1970-01-01
    相关资源
    最近更新 更多