您如何将变量输出到Ansible?

时间:2020-05-07 18:13:18

标签: ansible terraform

我遵循了此question中的答案,并且 我已经创建了一个template文件tf_ansible_vars_file.yml.tpl,如下所示

tf_share_location: "${share_location}"

和下面的terra_render.tf

# Define an Ansible var_file containing Terraform variable values
data "template_file" "tf_ansible_vars_file" {
  template = "${file("/home/deployment_root/app4/tf_ansible_vars_file.yml.tpl")}"
  vars = {
    share_location = var.share_location
    # gitlab_backup_bucket_name = aws_s3_bucket.gitlab_backup.bucket
  }
}

# Render the Ansible var_file containing Terrarorm variable values
resource "local_file" "tf_ansible_vars_file" {
  content  = data.template_file.tf_ansible_vars_file.rendered
  filename = "/home/deployment_root/app4/tf_ansible_vars_file.yml"
}

我已经有一个variables.tf文件,其中已经声明了该变量

variable "share_location" {
    type = string

}

,并且在terraform.tfvars中将值设为null

share_location = null

运行terraform apply时出现以下错误

Error: failed to render : <template_file>:1,23-37: Unknown variable; There is no variable named "share_location".

  on terra_render.tf line 2, in data "template_file" "tf_ansible_vars_file":
   2: data "template_file" "tf_ansible_vars_file" {

我的理解是它将创建该答案中提到的文件,但无法正常工作。

如何将变量输出到Ansible?

0 个答案:

没有答案