azure - 无法使用 Ansible 获取 Azure VM 专用 IP

标签 azure ansible ansible-2.x ansible-inventory ansible-facts

我正在尝试将 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/

相关文章:

database - 默认 getdate() 值错误 SQL AZURE

sql - 如何优化包含没有唯一值的字段的插入 SQL 查询?

git - 如何使用 PowerShell 在 Azure DevOps 管道中运行 git Push?

python - Ansible 解析 JSON 对象

ansible - 如何使用 ansible playbook 在 sudo 模式下运行命令?

ansible-2.x - Ansible 角色 : What content should I wtrite in `site.yml` and `webservers.yml` ?

c# - Azure Durable Functions 如何恢复?

ansible vars_files 与 include_vars

ansible - 将 Ansible 1.9.4 更新到 Ansible 2.0

Ansible - 找不到 pip