azure_rm_networkinterface - Manage Azure network interfaces.

New in version 2.1.

Synopsis

  • 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

The below requirements are needed on the host that executes this module.

  • python >= 2.7
  • azure >= 2.0.0

Parameters

Parameter Choices/Defaults Comments
ad_user Default:
None
Active Directory username. Use when authenticating with an Active Directory user rather than service principal.
api_profile
(added in 2.5)
    Choices:
  • latest
Selects an API profile to use when communicating with Azure services. Default value of latest is appropriate for public clouds; future values will allow use with Azure Stack.
append_tags Default:
yes
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.
auth_source
(added in 2.5)
    Choices:
  • auto
  • cli
  • credential_file
  • env
Controls the source of the credentials to use for authentication.
auto will follow the default precedence of module parameters -> environment variables -> default profile in credential file ~/.azure/credentials.
When set to cli, the credentials will be sources from the default Azure CLI profile.
Can also be set via the ANSIBLE_AZURE_AUTH_SOURCE environment variable.
cert_validation_mode
(added in 2.5)
    Choices:
  • validate
  • ignore
Default:
None
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 ignore. Can also be set via credential file profile or the AZURE_CERT_VALIDATION environment variable.
client_id Default:
None
Azure client ID. Use when authenticating with a Service Principal.
cloud_environment
(added in 2.4)
Default:
AzureCloud
For cloud environments other than the US public cloud, the environment name (as defined by Azure Python SDK, eg, AzureChinaCloud, AzureUSGovernment), or a metadata discovery endpoint URL (required for Azure Stack). Can also be set via credential file profile or the AZURE_CLOUD_ENVIRONMENT environment variable.
ip_configurations
(added in 2.5)
List of ip configuration if contains mutilple configuration, should contain configuration object include field private_ip_address, private_ip_allocation_method, public_ip_address_name, public_ip, subnet_name, virtual_network_name, public_ip_allocation_method, name
public_ip_address_name
Name of the public ip address. None for disable ip address.
private_ip_address
Private ip address for the ip configuration.
name
required
Name of the ip configuration.
private_ip_allocation_method
    Choices:
  • Dynamic
  • Static
private ip allocation method.
public_ip_allocation_method
    Choices:
  • Dynamic
  • Static
public ip allocation method.
primary Default:
no
Whether the ip configuration is the primary one in the list.
location Default:
resource_group location
Valid azure location. Defaults to location of the resource group.
name
required
Name of the network interface.
open_ports Default:
None
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 22, and for a Windows host rules will be added allowing inbound access to RDP ports 3389 and 5986. Override the default ports by providing a list of open ports.
os_type
    Choices:
  • Windows
  • Linux
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 os_type is 'Windows', a rule will be added allowing RDP access. If the os_type is 'Linux', a rule allowing SSH access will be added.
password Default:
None
Active Directory user password. Use when authenticating with an Active Directory user rather than service principal.
private_ip_address
(Deprecate) Valid IPv4 address that falls within the specified subnet.
This option will be deprecated in 2.9, use ip_configurations instead.
private_ip_allocation_method
    Choices:
  • Dynamic
  • Static
(Deprecate) Specify whether or not the assigned IP address is permanent. NOTE: when creating a network interface specifying a value of 'Static' requires that a private_ip_address value be provided. You can update the allocation method to 'Static' after a dynamic private ip address has been assigned.
This option will be deprecated in 2.9, use ip_configurations instead.
profile Default:
None
Security profile found in ~/.azure/credentials file.
public_ip Default:
yes
(Deprecate) When creating a network interface, if no public IP address name is provided a default public IP address will be created. Set to false, if you do not want a public IP address automatically created.
This option will be deprecated in 2.9, use ip_configurations instead.
public_ip_address_name Default:
None
(Deprecate) Name of an existing public IP address object to associate with the security group.
This option will be deprecated in 2.9, use ip_configurations instead.

aliases: public_ip_address, public_ip_name
public_ip_allocation_method
    Choices:
  • Dynamic
  • Static
(Deprecate) If a 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 ip_configurations instead.
resource_group
required
Name of a resource group where the network interface exists or will be created.
secret Default:
None
Azure client secret. Use when authenticating with a Service Principal.
security_group_name Default:
None
Name of an existing security group with which to associate the network interface. If not provided, a default security group will be created.

aliases: security_group
state
    Choices:
  • absent
  • present
Assert the state of the network interface. Use 'present' to create or update an interface and 'absent' to delete an interface.
subnet_name
required
Default:
None
Name of an existing subnet within the specified virtual network. Required when creating a network interface

aliases: subnet
subscription_id Default:
None
Your Azure subscription Id.
tags Default:
None
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.
tenant Default:
None
Azure tenant ID. Use when authenticating with a Service Principal.
virtual_network_name
required
Name or id of an existing virtual network with which the network interface will be associated. Required when creating a network interface.

aliases: virtual_network

Notes

Note

  • For authentication with Azure you can pass parameters, set environment variables or use a profile stored in ~/.azure/credentials. Authentication is possible using a service principal or Active Directory user. To authenticate via service principal, pass subscription_id, client_id, secret and tenant or set environment variables AZURE_SUBSCRIPTION_ID, AZURE_CLIENT_ID, AZURE_SECRET and AZURE_TENANT.
  • To authenticate via Active Directory user, pass ad_user and password, or set AZURE_AD_USER and AZURE_PASSWORD in the environment.
  • Alternatively, credentials can be stored in ~/.azure/credentials. This is an ini file containing a [default] section and the following keys: subscription_id, client_id, secret and tenant or subscription_id, ad_user and password. It is also possible to add additional profiles. Specify the profile by passing profile or setting AZURE_PROFILE in the environment.

Examples

- name: Create a network interface with minimal parameters
  azure_rm_networkinterface:
    name: nic001
    resource_group: Testing
    virtual_network_name: 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: Testing
    virtual_network_name: vnet001
    subnet_name: subnet001
    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: Testing
    virtual_network_name: vnet001
    subnet_name: subnet001
    os_type: Windows
    rdp_port: 3399
    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: Testing
    virtual_network_name: vnet001
    subnet_name: subnet001
    security_group_name: secgroup001
    ip_configurations:
      - name: ipconfig1
        public_ip_address_name: publicip001
        primary: True

- name: Create a network with mutilple ip configurations
  azure_rm_networkinterface:
    name: nic004
    resource_group: Testing
    subnet_name: subnet001
    virtual_network_name: vnet001
    security_group_name: secgroup001
    ip_configurations:
      - name: ipconfig1
        public_ip_address_name: publicip001
        primary: True
      - name: ipconfig2

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

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key Returned Description
state
dict
always
The current state of the network interface.

Sample:
{'dns_settings': {'dns_servers': [], 'internal_fqdn': None, 'internal_dns_name_label': None, 'applied_dns_servers': []}, 'name': 'nic003', 'tags': None, 'primary': None, 'enable_ip_forwarding': False, 'etag': 'W/"be115a43-2148-4545-a324-f33ad444c926"', 'location': 'eastus2', 'mac_address': None, 'ip_configurations': [{'subnet': {}, 'load_balancer_backend_address_pools': [], 'name': 'default', 'private_ip_allocation_method': 'Static', 'private_ip_address': '10.1.0.10', 'public_ip_address': {'id': '/subscriptions/XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/resourceGroups/Testing/providers/Microsoft.Network/publicIPAddresses/publicip001', 'name': 'publicip001'}}], 'provisioning_state': 'Succeeded', 'type': 'Microsoft.Network/networkInterfaces', 'id': '/subscriptions/XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/resourceGroups/Testing/providers/Microsoft.Network/networkInterfaces/nic003', 'network_security_group': {}}


Status

This module is flagged as preview which means that it is not guaranteed to have a backwards compatible interface.

Author

  • Chris Houseknecht (@chouseknecht)
  • Matt Davis (@nitzmahone)
  • Yuwei Zhou (@yuwzho)

Hint

If you notice any issues in this documentation you can edit this document to improve it.

© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.5/modules/azure_rm_networkinterface_module.html