Итак, у меня есть следующая Ansible playbook для выполнения скрипта Terraform:
- name: run Terraform
terraform:
project_path: "{{ terraform_base_dir }}"
force_init: yes
variables:
cp_key: "{{ cp_key }}"
cp_secret_key: "{{ cp_secret_key }}"
cluster_name: "{{ cluster_name }}"
template: "{{ template }}"
zone: "{{ zone }}"
size: "{{ size }}"
disk_size: "{{ disk_size }}"
key_pair: "{{ key_pair }}"
security_groups: "{{ security_groups }}"
и следующие Ansible переменные:
terraform_base_dir: "/root/deploy_k8s/terraform"
cp_key: "xxxxxxxxxxxxx"
cp_secret_key: "xxxxxxxxxxxxx"
cluster_name: "test123"
template: "Linux Ubuntu 18.04 LTS 64-bit"
zone: "at-vie-1"
size: "Medium"
disk_size: "100"
key_pair: "kp_xyz"
user: "ubuntu"
security_groups:
- "k8s-{{ cluster_name }}"
- "Jumphosts"
- "mobile_network"
- "home"
При выполнении playbook я получаю следующую ошибку:
fatal: [localhost]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"backend_config": null,
"binary_path": null,
"force_init": true,
"lock": true,
"lock_timeout": null,
"plan_file": null,
"project_path": "/root/deploy_k8s/terraform",
"purge_workspace": false,
"state": "present",
"state_file": null,
"targets": [],
"variables": {
"cluster_name": "test123",
"disk_size": "100",
"cp_key": "xxxxxxxxxxxxx",
"cp_secret_key": "xxxxxxxxxxxxx",
"key_pair": "kp_xyz",
"security_groups": [
"k8s-test123",
"Jumphosts",
"mobile_network",
"home"
],
"size": "Medium",
"template": "Linux Ubuntu 18.04 LTS 64-bit",
"zone": "at-vie-1"
},
"variables_file": null,
"workspace": "default"
}
},
"msg": "Terraform plan could not be created\r\nSTDOUT: Refreshing Terraform state in-memory prior to plan...\nThe refreshed state will be used to calculate this plan, but will not be\npersisted to local or remote state storage.\n\n\n------------------------------------------------------------------------\n\r\n\r\nSTDERR: \nError: Incorrect attribute value type\n\n on build.tf line 28, in resource \"cp_compute\" \"master\":\n 28: security_groups = \"${var.security_groups}\"\n\nInappropriate value for attribute \"security_groups\": set of string required.\n\n\nError: Incorrect attribute value type\n\n on build.tf line 38, in resource \"cp_compute\" \"node01\":\n 38: security_groups = \"${var.security_groups}\"\n\nInappropriate value for attribute \"security_groups\": set of string required.\n\n\nError: Incorrect attribute value type\n\n on build.tf line 48, in resource \"cp_compute\" \"node02\":\n 48: security_groups = \"${var.security_groups}\"\n\nInappropriate value for attribute \"security_groups\": set of string required.\n\n"
}
Недопустимое значение для атрибута "security_groups": необходим набор строк.
Файл Terraform "build.tf":
...
variable "security_groups" {}
...
resource "cp_compute" "master" {
display_name = "k8s-${var.cluster_name}-master"
template = "${var.template}"
zone = "${var.zone}"
size = "${var.size}"
disk_size = "${var.disk_size}"
key_pair = "${var.key_pair}"
security_groups = "${var.security_groups}"
}
...
Обеспечение групп безопасности, жестко запрограммированных в файле .tf, работает отлично.
security_groups = ["k8s-test123","Jumphosts","mobile_network","home"]
Предоставление точно таких же через переменную Ansible не работает.
Есть ли у кого-нибудь намеки, что не так с синтаксисом переменной?
Большое спасибо!