我正在尝试将 Ansible 创建的虚拟机的私有(private) IP 地址写入主机 list 中。但是,我无法找到 Ansible 的 Azure 私有(private) IP 属性。
下面是我用来获取远程主机的私有(private) IP 的代码,但 Ansible 没有获取远程主机的任何私有(private) IP
- name: Create virtual network inteface card
azure_rm_networkinterface:
resource_group: apache-corp
name: ansibleServerNIC
virtual_network: ansibleServerVnet
subnet: ansibleServerSubnet
public_ip_name: ansibleServerPublicIP
security_group: ansibleNetworkSecurityGroup
register: network_interface
- name: show private_ip
debug: "{{ network_interface.ip_configuration.private_ip_address }}"
Ansible 显示的错误:
"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'ip_configuration'\n\nT
最佳答案
这是我使用的代码:
- name: Get network interface details
azure_rm_networkinterface_facts:
resource_group: "{{vm.resource_group}}"
name: "{{vm.network_interface}}"
profile: "{{vm.azure_profile}}"
register: azure_networkinterfaces
delegate_to: localhost
- name: print internal IP
debug: msg="{{vm.vm_name}} internal ip is {{azure_networkinterfaces.ansible_facts.azure_networkinterfaces[0].properties.ipConfigurations[0].properties.privateIPAddress}}"
- name: set value of vm internal IP
set_fact:
vm_internal_ip: "{{azure_networkinterfaces.ansible_facts.azure_networkinterfaces[0].properties.ipConfigurations[0].properties.privateIPAddress}}"
关于azure - 无法使用 Ansible 获取 Azure VM 专用 IP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55501209/