我想使用local-exec
配置文件链接Terraform和Ansible;
但是,由于这需要输入 来自 Terraform的Ansible ,我会遇到以下复杂命令:
provisioner "local-exec" {
command = 'sleep 60; ansible-playbook -i ../ansible/inventory/ ../ansible/playbooks/site.yml --extra-vars "rancher_server_rds_endpoint="${aws_db_instance.my-server-rds.endpoint}" rancher_server_elastic_ip="${aws_eip.my-server-eip.public_ip}""'
}
继续返回
非法字符
误差;
有关正确逃避的任何建议吗?
如果要在shell中直接运行ansible-playbook
命令,那么它将是:
ansible-playbook -i inventory playbooks/site.yml --extra-vars "my_server_rds_endpoint=my-server-db.d30ikkj222.us-west-1.rds.amazonaws.com rancher_server_elastic_ip=88.148.17.236"
(路径不同)
答案 0 :(得分:3)
字符串是双引号。
所以你需要用双引号替换单引号,然后在里面转义引号,例如:
provisioner "local-exec" {
command = "sleep 60; ansible-playbook -i ../ansible/inventory/ ../ansible/playbooks/site.yml --extra-vars \"rancher_server_rds_endpoint='${aws_db_instance.my-server-rds.endpoint}' rancher_server_elastic_ip='${aws_eip.my-server-eip.public_ip}'\""
}