azure.azcollection.azure_rm_networkinterface (2.3.0) — module

Manage Azure network interfaces

| "added in version" 0.1.0 of azure.azcollection"

Authors: Chris Houseknecht (@chouseknecht), Matt Davis (@nitzmahone), Yuwei Zhou (@yuwzho)

Install collection

Install with ansible-galaxy collection install azure.azcollection:==2.3.0


Add to requirements.yml

  collections:
    - name: azure.azcollection
      version: 2.3.0

Description

Create, update or delete a network interface.

When creating a network interface you must provide the name of an existing virtual network, the name of an existing subnet within the virtual network.

A default security group and public IP address will be created automatically.

Or you can provide the name of an existing security group and public IP address.

See the examples below for more details.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
    public_ip: false
    ip_configurations:
      - name: default
        primary: true
        application_gateway_backend_address_pools:
          - name: myApplicationGatewayBackendAddressPool
            application_gateway: myApplicationGateway
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Delete network interface
  azure_rm_networkinterface:
    resource_group: myResourceGroup
    name: nic003
    state: absent

Inputs

    
name:
    description:
    - Name of the network interface.
    required: true
    type: str

tags:
    description:
    - Dictionary of string:string pairs to assign as metadata to the object.
    - Metadata tags on the object will be updated with any provided values.
    - To remove tags set append_tags option to false.
    - Currently, Azure DNS zones and Traffic Manager services also don't allow the use
      of spaces in the tag.
    - Azure Front Door doesn't support the use of
    - Azure Automation and Azure CDN only support 15 tags on resources.
    type: dict

state:
    choices:
    - absent
    - present
    default: present
    description:
    - Assert the state of the network interface. Use C(present) to create or update an
      interface and C(absent) to delete an interface.
    type: str

secret:
    description:
    - Azure client secret. Use when authenticating with a Service Principal.
    type: str

tenant:
    description:
    - Azure tenant ID. Use when authenticating with a Service Principal.
    type: str

ad_user:
    description:
    - Active Directory username. Use when authenticating with an Active Directory user
      rather than service principal.
    type: str

os_type:
    choices:
    - Windows
    - Linux
    default: Linux
    description:
    - Determines any rules to be added to a default security group.
    - When creating a network interface, if no security group name is provided, a default
      security group will be created.
    - If the I(os_type=Windows), a rule allowing RDP access will be added.
    - If the I(os_type=Linux), a rule allowing SSH access will be added.
    type: str

profile:
    description:
    - Security profile found in ~/.azure/credentials file.
    type: str

location:
    description:
    - Valid Azure location. Defaults to location of the resource group.
    type: str

log_mode:
    description:
    - Parent argument.
    type: str

log_path:
    description:
    - Parent argument.
    type: str

password:
    description:
    - Active Directory user password. Use when authenticating with an Active Directory
      user rather than service principal.
    type: str

client_id:
    description:
    - Azure client ID. Use when authenticating with a Service Principal or Managed Identity
      (msi).
    - Can also be set via the C(AZURE_CLIENT_ID) environment variable.
    type: str

public_ip:
    default: 'yes'
    description:
    - (Deprecate) When creating a network interface, if no public IP address name is provided
      a default public IP address will be created.
    - Set to C(false) if you do not want a public IP address automatically created.
    - This option will be deprecated in 2.9, use I(ip_configurations) instead.
    type: bool

open_ports:
    description:
    - When a default security group is created for a Linux host a rule will be added allowing
      inbound TCP connections to the default SSH port C(22), and for a Windows host rules
      will be added allowing inbound access to RDP ports C(3389) and C(5986). Override
      the default ports by providing a list of open ports.
    elements: str
    type: list

thumbprint:
    description:
    - The thumbprint of the private key specified in I(x509_certificate_path).
    - Use when authenticating with a Service Principal.
    - Required if I(x509_certificate_path) is defined.
    type: str
    version_added: 1.14.0
    version_added_collection: azure.azcollection

api_profile:
    default: latest
    description:
    - Selects an API profile to use when communicating with Azure services. Default value
      of C(latest) is appropriate for public clouds; future values will allow use with
      Azure Stack.
    type: str
    version_added: 0.0.1
    version_added_collection: azure.azcollection

append_tags:
    default: true
    description:
    - Use to control if tags field is canonical or just appends to existing tags.
    - When canonical, any tags not found in the tags parameter will be removed from the
      object's metadata.
    type: bool

auth_source:
    choices:
    - auto
    - cli
    - credential_file
    - env
    - msi
    default: auto
    description:
    - Controls the source of the credentials to use for authentication.
    - Can also be set via the C(ANSIBLE_AZURE_AUTH_SOURCE) environment variable.
    - When set to C(auto) (the default) the precedence is module parameters -> C(env)
      -> C(credential_file) -> C(cli).
    - When set to C(env), the credentials will be read from the environment variables
    - When set to C(credential_file), it will read the profile from C(~/.azure/credentials).
    - When set to C(cli), the credentials will be sources from the Azure CLI profile.
      C(subscription_id) or the environment variable C(AZURE_SUBSCRIPTION_ID) can be used
      to identify the subscription ID if more than one is present otherwise the default
      az cli subscription is used.
    - When set to C(msi), the host machine must be an azure resource with an enabled MSI
      extension. C(subscription_id) or the environment variable C(AZURE_SUBSCRIPTION_ID)
      can be used to identify the subscription ID if the resource is granted access to
      more than one subscription, otherwise the first subscription is chosen.
    - The C(msi) was added in Ansible 2.6.
    type: str
    version_added: 0.0.1
    version_added_collection: azure.azcollection

dns_servers:
    description:
    - Which DNS servers should the NIC lookup.
    - List of IP addresses.
    elements: str
    type: list

subnet_name:
    aliases:
    - subnet
    description:
    - Name of an existing subnet within the specified virtual network. Required when creating
      a network interface.
    - Use the C(virtual_network)'s resource group.
    - Required when creating.
    type: str

resource_group:
    description:
    - Name of a resource group where the network interface exists or will be created.
    required: true
    type: str

security_group:
    aliases:
    - security_group_name
    description:
    - An existing security group with which to associate the network interface.
    - If not provided, a default security group will be created when I(create_with_security_group=true).
    - It can be the name of security group.
    - Make sure the security group is in the same resource group when you only give its
      name.
    - It can be the resource id.
    - It can be a dict contains security_group's I(name) and I(resource_group).
    type: raw

subscription_id:
    description:
    - Your Azure subscription Id.
    type: str

virtual_network:
    aliases:
    - virtual_network_name
    description:
    - An existing virtual network with which the network interface will be associated.
      Required when creating a network interface.
    - It can be the virtual network's name.
    - Make sure your virtual network is in the same resource group as NIC when you give
      only the name.
    - It can be the virtual network's resource id.
    - It can be a dict which contains I(name) and I(resource_group) of the virtual network.
    - Required when creating.
    type: raw

cloud_environment:
    default: AzureCloud
    description:
    - For cloud environments other than the US public cloud, the environment name (as
      defined by Azure Python SDK, eg, C(AzureChinaCloud), C(AzureUSGovernment)), or a
      metadata discovery endpoint URL (required for Azure Stack). Can also be set via
      credential file profile or the C(AZURE_CLOUD_ENVIRONMENT) environment variable.
    type: str
    version_added: 0.0.1
    version_added_collection: azure.azcollection

ip_configurations:
    default: []
    description:
    - List of IP configurations. Each configuration object should include field I(private_ip_address),
      I(private_ip_allocation_method), I(public_ip_address_name), I(public_ip), I(public_ip_allocation_method),
      I(name).
    elements: dict
    suboptions:
      application_gateway_backend_address_pools:
        description:
        - List of existing application gateway backend address pools to associate with
          the network interface.
        - Can be written as a resource ID.
        - Also can be a dict of I(name) and I(application_gateway).
        elements: raw
        type: list
        version_added: 1.10.0
        version_added_collection: azure.azcollection
      application_security_groups:
        description:
        - List of application security groups in which the IP configuration is included.
        - Element of the list could be a resource id of application security group, or
          dict of I(resource_group) and I(name).
        elements: raw
        type: list
      load_balancer_backend_address_pools:
        description:
        - List of existing load-balancer backend address pools to associate with the network
          interface.
        - Can be written as a resource ID.
        - Also can be a dict of I(name) and I(load_balancer).
        elements: raw
        type: list
      name:
        description:
        - Name of the IP configuration.
        required: true
        type: str
      primary:
        default: false
        description:
        - Whether the IP configuration is the primary one in the list.
        - The first IP configuration default set to I(primary=True).
        type: bool
      private_ip_address:
        description:
        - Private IP address for the IP configuration.
        type: str
      private_ip_address_version:
        choices:
        - IPv4
        - IPv6
        default: IPv4
        description:
        - The version of the IP configuration.
        type: str
      private_ip_allocation_method:
        choices:
        - Dynamic
        - Static
        default: Dynamic
        description:
        - Private IP allocation method.
        type: str
      public_ip_address_name:
        aliases:
        - public_ip_address
        - public_ip_name
        description:
        - Name of the public IP address. None for disable IP address.
        type: str
      public_ip_allocation_method:
        choices:
        - Dynamic
        - Static
        default: Dynamic
        description:
        - Public IP allocation method.
        type: str
    type: list

adfs_authority_url:
    description:
    - Azure AD authority url. Use when authenticating with Username/password, and has
      your own ADFS authority.
    type: str
    version_added: 0.0.1
    version_added_collection: azure.azcollection

private_ip_address:
    description:
    - (Deprecate) Valid IPv4 address that falls within the specified subnet.
    - This option will be deprecated in 2.9, use I(ip_configurations) instead.
    type: str

cert_validation_mode:
    choices:
    - ignore
    - validate
    description:
    - Controls the certificate validation behavior for Azure endpoints. By default, all
      modules will validate the server certificate, but when an HTTPS proxy is in use,
      or against Azure Stack, it may be necessary to disable this behavior by passing
      C(ignore). Can also be set via credential file profile or the C(AZURE_CERT_VALIDATION)
      environment variable.
    type: str
    version_added: 0.0.1
    version_added_collection: azure.azcollection

enable_ip_forwarding:
    aliases:
    - ip_forwarding
    default: false
    description:
    - Whether to enable IP forwarding.
    type: bool

x509_certificate_path:
    description:
    - Path to the X509 certificate used to create the service principal in PEM format.
    - The certificate must be appended to the private key.
    - Use when authenticating with a Service Principal.
    type: path
    version_added: 1.14.0
    version_added_collection: azure.azcollection

public_ip_address_name:
    aliases:
    - public_ip_address
    - public_ip_name
    description:
    - (Deprecate) Name of an existing public IP address object to associate with the security
      group.
    - This option will be deprecated in 2.9, use I(ip_configurations) instead.
    type: str

create_with_security_group:
    default: true
    description:
    - Whether a security group should be be created with the NIC.
    - If this flag set to C(True) and no I(security_group) set, a default security group
      will be created.
    type: bool

disable_instance_discovery:
    default: false
    description:
    - Determines whether or not instance discovery is performed when attempting to authenticate.
      Setting this to true will completely disable both instance discovery and authority
      validation. This functionality is intended for use in scenarios where the metadata
      endpoint cannot be reached such as in private clouds or Azure Stack. The process
      of instance discovery entails retrieving authority metadata from https://login.microsoft.com/
      to validate the authority. By setting this to **True**, the validation of the authority
      is disabled. As a result, it is crucial to ensure that the configured authority
      host is valid and trustworthy.
    - Set via credential file profile or the C(AZURE_DISABLE_INSTANCE_DISCOVERY) environment
      variable.
    type: bool
    version_added: 2.3.0
    version_added_collection: azure.azcollection

public_ip_allocation_method:
    choices:
    - Dynamic
    - Static
    default: Dynamic
    description:
    - (Deprecate) If a I(public_ip_address_name) is not provided, a default public IP
      address will be created.
    - The allocation method determines whether or not the public IP address assigned to
      the network interface is permanent.
    - This option will be deprecated in 2.9, use I(ip_configurations) instead.
    type: str

private_ip_allocation_method:
    choices:
    - Dynamic
    - Static
    default: Dynamic
    description:
    - (Deprecate) Whether or not the assigned IP address is permanent.
    - When creating a network interface, if you specify I(private_ip_address=Static),
      you must provide a value for I(private_ip_address).
    - You can update the allocation method to C(Static) after a dynamic private IP address
      has been assigned.
    - This option will be deprecated in 2.9, use I(ip_configurations) instead.
    type: str

enable_accelerated_networking:
    default: false
    description:
    - Whether the network interface should be created with the accelerated networking
      feature or not.
    type: bool

Outputs

state:
  contains:
    dns_server:
      description:
      - Which DNS servers should the NIC lookup.
      - List of IP addresses.
      sample:
      - 8.9.10.11
      - 7.8.9.10
      type: list
    dns_setting:
      description:
      - The DNS settings in network interface.
      sample:
        applied_dns_servers: []
        dns_servers:
        - 8.9.10.11
        - 7.8.9.10
        internal_dns_name_label: null
        internal_fqdn: null
      type: dict
    enable_accelerated_networking:
      description:
      - Whether the network interface should be created with the accelerated networking
        feature or not.
      sample: true
      type: bool
    enable_ip_forwarding:
      description: Whether to enable IP forwarding.
      sample: true
      type: bool
    etag:
      description:
      - A unique read-only string that changes whenever the resource is updated.
      sample: W/"be115a43-2148-4545-a324-f33ad444c926"
      type: str
    id:
      description:
      - Id of the network interface.
      sample: /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroup/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nic003
      type: str
    ip_configurations:
      contains:
        application_gateway_backend_address_pools:
          description:
          - List of existing application gateway backend address pool resource IDs
            associated with the network interface.
          sample:
          - /subscriptions/xxx/resourceGroups/myResourceGroup/providers/Microsoft.Network/applicationGateways/myGateway/
            backendAddressPools/myBackendAddressPool
          type: list
          version_added: 1.10.0
          version_added_collection: azure.azcollection
        load_balancer_backend_address_pools:
          description:
          - List of existing load-balancer backend address pools associated with the
            network interface.
          type: list
        name:
          description:
          - Name of the IP configuration.
          sample: default
          type: str
        private_ip_address:
          description:
          - Private IP address for the IP configuration.
          sample: 10.1.0.10
          type: str
        private_ip_address_version:
          description:
          - The version of the IP configuration.
          sample: IPv4
          type: str
        private_ip_allocation_method:
          description:
          - Private IP allocation method.
          sample: Static
          type: str
        public_ip_address:
          description:
          - Name of the public IP address. None for disable IP address.
          sample:
            id: /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroup/myResourceGroup/providers/Microsoft.Network/publicIPAddresse
              s/publicip001
            name: publicip001
          type: dict
        subnet:
          description:
          - The reference of the subnet resource.
          sample:
            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
          type: dict
      description:
      - List of IP configurations.
      type: complex
    location:
      description:
      - The network interface resource location.
      sample: eastus
      type: str
    mac_address:
      description:
      - The MAC address of the network interface.
      type: str
    name:
      description:
      - Name of the network interface.
      sample: nic003
      type: str
    network_security_group:
      description:
      - The reference of the network security group resource.
      sample:
        id: /subscriptions//xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroup/ myResourceGroup/providers/Microsoft.Network/networkSecurityGroups/nsg001
        name: nsg001
      type: dict
    primary:
      description:
      - Get whether this is a primary network interface on virtual machine.
      sample: true
      type: bool
    provisioning_state:
      description:
      - The provisioning state of the public IP resource.
      sample: Succeeded
      type: str
    tags:
      description: -Tags of the network interface.
      sample:
        key: value
      type: dict
    type:
      description:
      - Type of the resource.
      sample: Microsoft.Network/networkInterfaces
      type: str
  description:
  - The current state of the network interface.
  returned: always
  type: complex

See also