【问题标题】:ansible failed with 'dict object' has no attribute 'ipAddressansible 失败,'dict object' 没有属性'ipAddress
【发布时间】:2021-04-29 09:09:13
【问题描述】:

我试图通过参考以下文档来配置 Azure 应用程序网关。 https://docs.microsoft.com/en-us/azure/developer/ansible/application-gateway-configure?tabs=ansible 但我没有使用容器,而是使用虚拟机作为后端池。

- name: Get info of backend server 1
  azure_rm_resource_info:
    api_version: '2018-04-01'
    resource_group: "{{ resource_group }}"
    provider: compute
    resource_type: virtualmachines
    resource_name: "{{ vm_1_name }}"
  register: vm_1_output


- name: Create instance of Application Gateway
  azure_rm_appgateway:
    resource_group: "{{ resource_group }}"
    name: "{{ appgw_name }}"
    frontend_ip_configurations:
      - public_ip_address: "publicip-{{env}}-{{appgw_name}}"
        name: appGatewayFrontendIP
    frontend_ports:
      - port: 80
        name: appGatewayFrontendPort
    backend_address_pools:
      - backend_addresses:
          - ip_address: "{{ vm_1_output.response[0].properties.ipAddress.ip }}"
        name: appGatewayBackendPool

但我收到以下错误。

"The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'ipAddress'\n\nThe error appears to be in

我已尝试更改值 IpAddress.ip、IPAddress.ip 和 private_ip_address.id 但仍然失败。任何帮助将不胜感激。

谢谢

【问题讨论】:

  • 可以发vm_1_output的样本数据结构吗?或者,如果您已经完成了debug 的操作,可以深入了解response[0].properties 的内容?是否有密钥ipAddress
  • 这个运气好吗?您有机会检查提供的解决方案吗?

标签: azure ansible


【解决方案1】:

查看 Ansible 中 azure_rm_resource_info 模块的 return values,响应中似乎没有返回 ipaddress 属性。

使用azure_rm_networkinterface_info 模块获取连接到虚拟机的网络接口的事实,以检索IP address。然后,您应该能够使用类似于以下内容的表达式访问 IP:networkinterface_output.networkinterfaces[0].ip_configurations[0].private_ip_address

查看讨论类似问题的this SO 帖子。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-18
    • 2018-10-28
    • 1970-01-01
    • 1970-01-01
    • 2020-10-16
    • 1970-01-01
    相关资源
    最近更新 更多