azure.azcollection.azure_rm_networkinterface 模块 – 管理 Azure 网络接口

注意

此模块是 azure.azcollection 集合 (版本 3.1.0) 的一部分。

如果您使用的是 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install azure.azcollection。要使用此模块,您需要其他要求,请参阅 要求 以了解详情。

要在 playbook 中使用它,请指定:azure.azcollection.azure_rm_networkinterface

azure.azcollection 0.1.0 中的新增功能

概要

  • 创建、更新或删除网络接口。

  • 创建网络接口时,必须提供现有虚拟网络的名称和虚拟网络中现有子网的名称。

  • 默认安全组和公有 IP 地址将自动创建。

  • 或者,您可以提供现有安全组和公有 IP 地址的名称。

  • 有关更多详细信息,请参见下面的示例。

要求

执行此模块的主机需要以下要求。

  • python >= 2.7

  • 执行此模块的主机必须通过 galaxy 安装 azure.azcollection 集合

  • 集合的 requirements.txt 中列出的所有 Python 包都必须通过 pip 安装在执行 azure.azcollection 集合中模块的主机上

  • 完整的安装说明可在 https://galaxy.ansible.com/azure/azcollection 找到

参数

参数

注释

ad_user

字符串

Active Directory 用户名。使用 Active Directory 用户而不是服务主体进行身份验证时使用。

adfs_authority_url

字符串

azure.azcollection 0.0.1 中新增

Azure AD 授权 URL。使用用户名/密码进行身份验证时使用,并拥有您自己的 ADFS 授权。

api_profile

字符串

azure.azcollection 0.0.1 中新增

选择与 Azure 服务通信时要使用的 API 配置文件。对于公有云,latest 的默认值是合适的;未来的值将允许与 Azure Stack 一起使用。

默认值: "latest"

append_tags

布尔值

用于控制标签字段是规范的还是只是附加到现有标签。

如果为规范,则在 tags 参数中找不到的任何标签都将从对象的元数据中删除。

选项

  • false

  • true ← (默认)

auth_source

字符串

azure.azcollection 0.0.1 中新增

控制用于身份验证的凭据来源。

也可以通过 ANSIBLE_AZURE_AUTH_SOURCE 环境变量设置。

设置为 auto(默认值)时,优先级为模块参数 -> env -> credential_file -> cli

设置为 env 时,凭据将从环境变量中读取。

设置为 credential_file 时,它将从 ~/.azure/credentials 读取配置文件。

设置为 cli 时,凭据将从 Azure CLI 配置文件中获取。如果存在多个订阅,则可以使用 subscription_id 或环境变量 AZURE_SUBSCRIPTION_ID 来标识订阅 ID,否则使用默认的 az cli 订阅。

设置为 msi 时,主机必须是启用了 MSI 扩展的 Azure 资源。subscription_id 或环境变量 AZURE_SUBSCRIPTION_ID 可用于标识资源被授予访问权限的多个订阅中的订阅 ID,否则选择第一个订阅。

msi 在 Ansible 2.6 中添加。

选项

  • "auto" ← (默认)

  • "cli"

  • "credential_file"

  • "env"

  • "msi"

cert_validation_mode

字符串

azure.azcollection 0.0.1 中新增

控制 Azure 端点的证书验证行为。默认情况下,所有模块都将验证服务器证书,但在使用 HTTPS 代理或针对 Azure Stack 时,可能需要通过传递 ignore 来禁用此行为。也可以通过凭据文件配置文件或 AZURE_CERT_VALIDATION 环境变量设置。

选项

  • "ignore"

  • "validate"

client_id

字符串

Azure 客户端 ID。使用服务主体或托管身份 (msi) 进行身份验证时使用。

也可以通过 AZURE_CLIENT_ID 环境变量设置。

cloud_environment

字符串

azure.azcollection 0.0.1 中新增

对于美国公有云以外的云环境,环境名称(由 Azure Python SDK 定义,例如 AzureChinaCloudAzureUSGovernment)或元数据发现端点 URL(Azure Stack 需要)。也可以通过凭据文件配置文件或 AZURE_CLOUD_ENVIRONMENT 环境变量设置。

默认值: "AzureCloud"

create_with_security_group

布尔值

是否应使用 NIC 创建安全组。

如果此标志设置为 True 且未设置 *security_group*,则将创建一个默认安全组。

选项

  • false

  • true ← (默认)

disable_instance_discovery

布尔值

azure.azcollection 2.3.0 中新增

确定在尝试进行身份验证时是否执行实例发现。将其设置为 true 将完全禁用实例发现和授权验证。此功能旨在用于无法访问元数据端点的场景,例如私有云或 Azure Stack。实例发现过程需要从 https://login.microsoft.com/ 获取授权元数据以验证授权。通过将其设置为 **True**,授权验证将被禁用。因此,务必确保已配置的授权主机有效且值得信赖。

通过凭据文件配置文件或 AZURE_DISABLE_INSTANCE_DISCOVERY 环境变量设置。

选项

  • false ← (默认)

  • true

dns_servers

列表 / 元素=字符串

NIC 应查找哪些 DNS 服务器。

IP 地址列表。

enable_accelerated_networking

布尔值

网络接口是否应使用加速网络功能创建。

选项

  • false ← (默认)

  • true

enable_ip_forwarding

别名:ip_forwarding

布尔值

是否启用 IP 转发。

选项

  • false ← (默认)

  • true

ip_configurations

列表 / 元素=字典

IP 配置列表。每个配置对象应包含字段 *private_ip_address*、*private_ip_allocation_method*、*public_ip_address_name*、*public_ip*、*public_ip_allocation_method*、*name*。

默认: []

application_gateway_backend_address_pools

列表 / 元素=任意

azure.azcollection 1.10.0 中添加

要与网络接口关联的现有应用程序网关后端地址池列表。

可以写成资源 ID。

也可以是包含 *name* 和 *application_gateway* 字段的字典。

application_security_groups

列表 / 元素=任意

包含 IP 配置的应用程序安全组列表。

列表的元素可以是应用程序安全组的资源 ID,也可以是当前资源组中应用程序安全组的名称,或者是一个包含资源组和名称的字典。

load_balancer_backend_address_pools

列表 / 元素=任意

要与网络接口关联的现有负载均衡器后端地址池列表。

可以写成资源 ID。

也可以是包含 *name* 和 *load_balancer* 字段的字典。

name

字符串 / 必填

IP 配置的名称。

primary

布尔值

IP 配置是否是列表中的主要配置。

第一个 IP 配置默认设置为 *primary=True*。

选项

  • false ← (默认)

  • true

private_ip_address

字符串

IP 配置的私有 IP 地址。

private_ip_address_version

字符串

IP 配置的版本。

选项

  • "IPv4" ← (默认)

  • "IPv6"

private_ip_allocation_method

字符串

私有 IP 分配方法。

选项

  • "Dynamic" ← (默认)

  • "Static"

public_ip_address_name

别名:public_ip_address, public_ip_name

字符串

公有 IP 地址的名称。禁用 IP 地址时为 None。

public_ip_allocation_method

字符串

公有 IP 分配方法。

选项

  • "Dynamic" ← (默认)

  • "Static"

location

字符串

有效的 Azure 位置。默认为资源组的位置。

log_mode

字符串

父参数。

log_path

字符串

父参数。

name

字符串 / 必填

网络接口的名称。

open_ports

列表 / 元素=字符串

为 Linux 主机创建默认安全组时,将添加一条规则,允许传入 TCP 连接到默认 SSH 端口 22,而对于 Windows 主机,将添加规则,允许传入访问 RDP 端口 33895986。通过提供打开端口列表来覆盖默认端口。

os_type

字符串

确定要添加到默认安全组的任何规则。

创建网络接口时,如果未提供安全组名称,则将创建一个默认安全组。

如果 *os_type=Windows*,则将添加允许 RDP 访问的规则。

如果 *os_type=Linux*,则将添加允许 SSH 访问的规则。

选项

  • "Windows"

  • "Linux" ← (默认)

password

字符串

Active Directory 用户密码。使用此密码通过 Active Directory 用户而不是服务主体进行身份验证。

profile

字符串

在 ~/.azure/credentials 文件中找到的安全配置文件。

resource_group

字符串 / 必填

存在或将创建网络接口的资源组的名称。

secret

字符串

Azure 客户机密钥。使用此密钥通过服务主体进行身份验证。

security_group

别名:security_group_name

任意

要与其关联网络接口的现有安全组。

如果未提供,则当 *create_with_security_group=true* 时将创建一个默认安全组。

它可以是安全组的名称。

仅提供安全组名称时,请确保安全组位于相同的资源组中。

它可以是资源 ID。

它可以是包含安全组的 *name* 和 *resource_group* 字段的字典。

state

字符串

声明网络接口的状态。使用 present 创建或更新接口,使用 absent 删除接口。

选项

  • "absent"

  • "present" ← (默认)

subnet_name

别名:subnet

字符串

指定虚拟网络中现有子网的名称。创建网络接口时必填。

使用 virtual_network 的资源组。

创建时必填。

subscription_id

字符串

您的 Azure 订阅 ID。

tags

字典

字符串:字符串对的字典,用作对象的元数据。

对象的元数据标签将使用任何提供的数值更新。

要删除标签,请将 append_tags 选项设置为 false。

目前,Azure DNS 区域和流量管理器服务也不允许在标签中使用空格。

Azure 前端门户不支持使用

Azure 自动化和 Azure CDN 资源上仅支持 15 个标签。

tenant

字符串

Azure 租户 ID。使用此 ID 通过服务主体进行身份验证。

thumbprint

字符串

azure.azcollection 1.14.0 中添加

在 *x509_certificate_path* 中指定的私钥的指纹。

使用此指纹通过服务主体进行身份验证。

如果定义了 *x509_certificate_path*,则必填。

virtual_network

别名:virtual_network_name

任意

要与其关联网络接口的现有虚拟网络。创建网络接口时必填。

它可以是虚拟网络的名称。

仅提供名称时,请确保虚拟网络与 NIC 位于相同的资源组中。

它可以是虚拟网络的资源 ID。

它可以是包含虚拟网络的 *name* 和 *resource_group* 字段的字典。

创建时必填。

x509_certificate_path

路径

azure.azcollection 1.14.0 中添加

PEM 格式下用于创建服务主体的 X509 证书的路径。

证书必须附加到私钥。

使用此指纹通过服务主体进行身份验证。

注释

注意

  • 对于使用 Azure 进行身份验证,您可以传递参数、设置环境变量、使用存储在 ~/.azure/credentials 中的配置文件,或者在运行任务或剧本之前使用 az login 登录。

  • 也可以使用服务主体或 Active Directory 用户进行身份验证。

  • 要通过服务主体进行身份验证,请传递 subscription_id、client_id、secret 和 tenant,或者设置环境变量 AZURE_SUBSCRIPTION_ID、AZURE_CLIENT_ID、AZURE_SECRET 和 AZURE_TENANT。

  • 要通过 Active Directory 用户进行身份验证,请传递 ad_user 和 password,或者在环境中设置 AZURE_AD_USER 和 AZURE_PASSWORD。

  • 或者,凭据可以存储在 ~/.azure/credentials 中。这是一个包含 [default] 部分和以下键的 ini 文件:subscription_id、client_id、secret 和 tenant 或 subscription_id、ad_user 和 password。也可以添加其他配置文件。通过传递 profile 或在环境中设置 AZURE_PROFILE 来指定配置文件。

另请参阅

另请参阅

使用 Azure CLI 登录

如何使用 az login 命令进行身份验证。

示例

- name: Create a network interface with minimal parameters
  azure_rm_networkinterface:
    name: nic001
    resource_group: myResourceGroup
    virtual_network: vnet001
    subnet_name: subnet001
    ip_configurations:
      - name: ipconfig1
        public_ip_address_name: publicip001
        primary: true

- name: Create a network interface with private IP address only (no Public IP)
  azure_rm_networkinterface:
    name: nic001
    resource_group: myResourceGroup
    virtual_network: vnet001
    subnet_name: subnet001
    create_with_security_group: false
    ip_configurations:
      - name: ipconfig1
        primary: true

- name: Create a network interface for use in a Windows host (opens RDP port) with custom RDP port
  azure_rm_networkinterface:
    name: nic002
    resource_group: myResourceGroup
    virtual_network: vnet001
    subnet_name: subnet001
    os_type: Windows
    rdp_port: 3399
    security_group: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroup/myResourceGroup/providers/Microsoft.Network/networkSecurit
                     yGroups/nsg001"
    ip_configurations:
      - name: ipconfig1
        public_ip_address_name: publicip001
        primary: true

- name: Create a network interface using existing security group and public IP
  azure_rm_networkinterface:
    name: nic003
    resource_group: myResourceGroup
    virtual_network: vnet001
    subnet_name: subnet001
    security_group: secgroup001
    ip_configurations:
      - name: ipconfig1
        public_ip_address_name: publicip001
        primary: true

- name: Create a network with multiple ip configurations
  azure_rm_networkinterface:
    name: nic004
    resource_group: myResourceGroup
    subnet_name: subnet001
    virtual_network: vnet001
    security_group:
      name: testnic002
      resource_group: Testing1
    ip_configurations:
      - name: ipconfig1
        public_ip_address_name: publicip001
        primary: true
      - name: ipconfig2
        load_balancer_backend_address_pools:
          - "{{ loadbalancer001.state.backend_address_pools[0].id }}"
          - name: backendaddrpool1
            load_balancer: loadbalancer001

- name: Create network interface attached to application gateway backend address pool
  azure_rm_networkinterface:
    name: nic-appgw
    resource_group: myResourceGroup
    virtual_network: vnet001
    subnet_name: subnet001
    create_with_security_group: false
    ip_configurations:
      - name: default
        primary: true
        application_gateway_backend_address_pools:
          - name: myApplicationGatewayBackendAddressPool
            application_gateway: myApplicationGateway

- name: Create a network interface in accelerated networking mode
  azure_rm_networkinterface:
    name: nic005
    resource_group: myResourceGroup
    virtual_network_name: vnet001
    subnet_name: subnet001
    enable_accelerated_networking: true

- name: Create a network interface with IP forwarding
  azure_rm_networkinterface:
    name: nic001
    resource_group: myResourceGroup
    virtual_network: vnet001
    subnet_name: subnet001
    ip_forwarding: true
    ip_configurations:
      - name: ipconfig1
        public_ip_address_name: publicip001
        primary: true

- name: Create a network interface with dns servers
  azure_rm_networkinterface:
    name: nic009
    resource_group: myResourceGroup
    virtual_network: vnet001
    subnet_name: subnet001
    dns_servers:
      - 8.8.8.8

- name: Delete network interface
  azure_rm_networkinterface:
    resource_group: myResourceGroup
    name: nic003
    state: absent

返回值

常见返回值已在此处记录,以下是此模块特有的字段

描述

state

复杂

网络接口的当前状态。

返回:始终

dns_server

列表 / 元素=字符串

NIC 应查找哪些 DNS 服务器。

IP 地址列表。

返回:成功

示例: ["8.9.10.11", "7.8.9.10"]

dns_setting

字典

网络接口中的 DNS 设置。

返回:成功

示例: {"applied_dns_servers": [], "dns_servers": ["8.9.10.11", "7.8.9.10"], "internal_dns_name_label": null, "internal_fqdn": null}

enable_accelerated_networking

布尔值

网络接口是否应使用加速网络功能创建。

返回:成功

示例: true

enable_ip_forwarding

布尔值

是否启用 IP 转发。

返回:成功

示例: true

etag

字符串

每当资源更新时都会更改的唯一只读字符串。

返回:成功

示例: "W/\"be115a43-2148-4545-a324-f33ad444c926\""

id

字符串

网络接口的 ID。

返回:成功

示例: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroup/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nic003"

ip_configurations

复杂

IP 配置列表。

返回:成功

application_gateway_backend_address_pools

列表 / 元素=字符串

azure.azcollection 1.10.0 中添加

与网络接口关联的现有应用程序网关后端地址池资源 ID 列表。

返回:成功

示例: ["/subscriptions/xxx/resourceGroups/myResourceGroup/providers/Microsoft.Network/applicationGateways/myGateway/ backendAddressPools/myBackendAddressPool"]

load_balancer_backend_address_pools

列表 / 元素=字符串

与网络接口关联的现有负载均衡器后端地址池列表。

返回:成功

name

字符串

IP 配置的名称。

返回:成功

示例: "default"

private_ip_address

字符串

IP 配置的私有 IP 地址。

返回:成功

示例: "10.1.0.10"

private_ip_address_version

字符串

IP 配置的版本。

返回:成功

示例: "IPv4"

private_ip_allocation_method

字符串

私有 IP 分配方法。

返回:成功

示例: "Static"

public_ip_address

字典

公有 IP 地址的名称。禁用 IP 地址时为 None。

返回:成功

示例: {"id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroup/myResourceGroup/providers/Microsoft.Network/publicIPAddresse s/publicip001", "name": "publicip001"}

subnet

字典

子网资源的引用。

返回:成功

示例: {"id": "/subscriptions/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/ myresourcegroup/providers/Microsoft.Network/virtualNetworks/tnb57dc95318/subnets/tnb57dc95318", "name": "tnb57dc95318", "resource_group": "myresourcegroup", "virtual_network_name": "tnb57dc95318"}

location

字符串

网络接口资源位置。

返回:成功

示例: "eastus"

mac_address

字符串

网络接口的MAC地址。

返回:成功

name

字符串

网络接口的名称。

返回:成功

示例: "nic003"

network_security_group

字典

网络安全组资源的引用。

返回:成功

示例: {"id": "/subscriptions//xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroup/ myResourceGroup/providers/Microsoft.Network/networkSecurityGroups/nsg001", "name": "nsg001"}

primary

布尔值

获取该网络接口是否是虚拟机上的主网络接口。

返回:成功

示例: true

provisioning_state

字符串

公网IP资源的预配状态。

返回:成功

示例: "Succeeded"

tags

字典

网络接口的标签。

返回:成功

示例: {"key": "value"}

type

字符串

资源类型。

返回:成功

示例: "Microsoft.Network/networkInterfaces"

作者

  • Chris Houseknecht (@chouseknecht)

  • Matt Davis (@nitzmahone)

  • 周宇威 (@yuwzho)