【问题标题】:Azure_rm.py: skipping: no hosts matchedAzure_rm.py:跳过:没有匹配的主机
【发布时间】: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


【解决方案1】:

在 azure_rm.ini 文件中写入“tags=zookeepernodes,kafkanodes”:

tags=role:zookeepernodes

您还可以通过以下方式包含 kafkanodes 节点:

tags=role:zookeepernodes,role:kafkanodes

它是“键:值”。在您的情况下,角色是一个键,而 zookeepernodes 是一个值。

【讨论】:

  • 感谢您的快速回复@GregS。尝试了建议的建议:
  • 感谢您的快速回复@GregS。尝试使用 azure_rm.ini 中的键/值进行建议推荐。但是,仍然得到以下信息:“azurerm_virtual_machine.bastion[1](远程执行):[警告]:无法匹配提供的主机模式,忽略:zookeepernodes azurerm_virtual_machine.bastion[1](远程执行):azurerm_virtual_machine.bastion[ 1](远程执行):[警告]:无法匹配提供的主机模式,忽略:kafkanodes"
猜你喜欢
  • 2014-01-15
  • 2022-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-01
相关资源
最近更新 更多