我正在尝试将Ansible创建的虚拟机的专用IP地址写入主机清单。然而,我找不到Ansible的Azure私有IP属性。
下面是我用来获取远程主机的内网IP的代码,但Ansible没有获取任何远程主机的内网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发布于 2019-07-03 00:42:23
这是我使用的代码:
- 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}}"发布于 2020-10-19 16:50:39
我不得不使用一些不同的代码,因为由于某种原因,我不能让示例工作。
- name: Get facts for one network interface
azure_rm_networkinterface_info:
resource_group: "{{ vm_resource_group }}"
name: "{{ vm_name }}-nic"
register: networkinterface_output
- name: set value of vm internal IP
set_fact:
vm_internal_ip: "{{ networkinterface_output.networkinterfaces[0].ip_configurations[0].private_ip_address}}"希望这能帮助到一些人。Ansible,networkinterface_info
https://stackoverflow.com/questions/55501209
复制相似问题