无法使用 Ansible 获取 Azure VM 私有 IP [英] Not able to get Azure VM private IP using Ansible

查看:43
本文介绍了无法使用 Ansible 获取 Azure VM 私有 IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 Ansible 创建的虚拟机的私有 IP 地址写入主机清单.但是,我找不到 Ansible 的 Azure 私有 IP 属性.

I am trying to write the Private IP address of virtual machine created by Ansible into host inventory. However, I wasn't able to find Azure private IP property for Ansible.

下面是我用来获取远程主机私有 IP 的代码,但 Ansible 没有获取远程主机的任何私有 IP

Below is the code that I am using to fetch the private IP of remote host but Ansible is not fetching any private IP of remote host

- 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 显示的错误:

Error that Ansible shows:

"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}}"

这篇关于无法使用 Ansible 获取 Azure VM 私有 IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆