【发布时间】:2023-04-01 03:24:02
【问题描述】:
环境:
Ansible version: 2.4
Component name: azure_rm
Cloud: Azure
Terraform:0.11.1
Provider: azure_rm v0.3.3
尝试使用 azure_rm.py 进行 ansible 工作,但由于某种原因,它没有处理我随 terraform 提供的标签。
我在我的 terraform 文件中创建了这样的标签:
tags {
environment = "${var.environment_tag}"
role = "${var.zookeeper_role_tag}"
}
在 variables.tf 我有以下内容:
variable "zookeeper_role_tag" {
description = "ZooKeeper Role Tag"
default = "zookeepernodes"
}
现在,在我的 azure_rm.ini 中,我有以下条目:
[azure]
# Control which resource groups are included. By default all resources groups are included.
# Set resource_groups to a comma separated list of resource groups names.
resource_groups=rgTest
# Control which tags are included. Set tags to a comma separated list of keys or key:value pairs
#tags=zookeeper_role_tag:zookeepernodes,broker_role_tag:kafkanodes
tags=zookeepernodes,kafkanodes
# Control which locations are included. Set locations to a comma separated list (e.g. eastus,eastus2,westus)
locations=eastus
# Include powerstate. If you don't need powerstate information, turning it off improves runtime performance.
include_powerstate=yes
# Control grouping with the following boolean flags. Valid values: yes, no, true, false, True, False, 0, 1.
group_by_resource_group=yes
group_by_location=yes
group_by_security_group=yes
group_by_tag=yes
我使用 terraform 的 remote-exec 执行脚本:
provisioner "remote-exec" {
inline =
"ansible-playbook -i ~/ansible/contrib/inventory/azure_rm.py ~/${var.ansible_file}/ansible_kafka.yml -e 'ansible_user=ansible01 ansible_group=ansgroup kafka_user=kafkauser kafka_group=kafkagroup zookeeper_user=kafkauser zookeeper_group=kafkagroup"
]
}
但是,我收到以下错误:
azurerm_virtual_machine.bastion[0] (remote-exec): PLAY [zookeepernodes:kafkanodes]
***********************************************
azurerm_virtual_machine.bastion[0] (remote-exec): skipping: no hosts matched
azurerm_virtual_machine.bastion[0] (remote-exec): PLAY [zookeepernodes]
**********************************************************
azurerm_virtual_machine.bastion[0] (remote-exec): skipping: no hosts matched
azurerm_virtual_machine.bastion[0] (remote-exec): PLAY [kafkanodes]
**************************************************************
azurerm_virtual_machine.bastion[0] (remote-exec): skipping: no hosts matched
azurerm_virtual_machine.bastion[0] (remote-exec): PLAY [all]
*********************************************************************
azurerm_virtual_machine.bastion.0: Still creating... (4m50s elapsed)
如上所示,azure_rm.py 没有拾取标记节点 (zookeepernodes, kafkanodes)。
任何指针我做错了什么?再次感谢!!
【问题讨论】:
-
"如上图所示,azure_rm.py 没有选择" -- 上面我看到了除了
~/ansible/contrib/inventory/azure_rm.py的输出之外的所有内容 -
感谢@techraf 的快速回复。我正在使用 vanilla contrib/inventory/azure_rm.py,但使用 azure_rm.ini 覆盖变量。所以在某种程度上,我并没有改变原始图像中的 azure_rm.py。不知道是对是错,但这是我从阅读中得到的想法。
标签: ansible terraform terraform-provider-azure