@ -193,6 +193,12 @@ options:
type : bool
default : False
version_added : 2.7
dns_servers :
description :
- Which DNS servers should the NIC lookup
- List of IP ' s
type : list
version_added : 2.7
extends_documentation_fragment :
- azure
- azure_tags
@ -291,6 +297,15 @@ EXAMPLES = '''
public_ip_address_name : publicip001
primary : True
- name : Create a network interface with dns servers
azure_rm_networkinterface :
name : nic009
resource_group : Testing
virtual_network : vnet001
subnet_name : subnet001
dns_servers :
- 8.8 .8 .8
- name : Delete network interface
azure_rm_networkinterface :
resource_group : Testing
@ -399,6 +414,7 @@ def nic_to_dict(nic):
provisioning_state = nic . provisioning_state ,
etag = nic . etag ,
enable_accelerated_networking = nic . enable_accelerated_networking ,
dns_servers = nic . dns_settings . dns_servers ,
)
@ -436,6 +452,7 @@ class AzureRMNetworkInterface(AzureRMModuleBase):
os_type = dict ( type = ' str ' , choices = [ ' Windows ' , ' Linux ' ] , default = ' Linux ' ) ,
open_ports = dict ( type = ' list ' ) ,
enable_ip_forwarding = dict ( type = ' bool ' , aliases = [ ' ip_forwarding ' ] , default = False ) ,
dns_servers = dict ( type = ' list ' ) ,
)
required_if = [
@ -461,6 +478,7 @@ class AzureRMNetworkInterface(AzureRMModuleBase):
self . open_ports = None
self . enable_ip_forwarding = None
self . ip_configurations = None
self . dns_servers = None
self . results = dict (
changed = False ,
@ -540,6 +558,16 @@ class AzureRMNetworkInterface(AzureRMModuleBase):
results . get ( ' enable_ip_forwarding ' ) ) )
changed = True
# We need to ensure that dns_servers are list like
dns_servers_res = results . get ( ' dns_settings ' ) . get ( ' dns_servers ' )
_dns_servers_set = sorted ( self . dns_servers ) if isinstance ( self . dns_servers , list ) else list ( )
_dns_servers_res = sorted ( dns_servers_res ) if isinstance ( self . dns_servers , list ) else list ( )
if _dns_servers_set != _dns_servers_res :
self . log ( " CHANGED: DNS servers set to {0} (previously {1} ) " . format (
" , " . join ( _dns_servers_set ) ,
" , " . join ( _dns_servers_res ) ) )
changed = True
if not changed :
nsg = self . get_security_group ( self . security_group [ ' resource_group ' ] , self . security_group [ ' name ' ] )
if nsg and results . get ( ' network_security_group ' ) and results [ ' network_security_group ' ] . get ( ' id ' ) != nsg . id :
@ -622,6 +650,10 @@ class AzureRMNetworkInterface(AzureRMModuleBase):
enable_ip_forwarding = self . enable_ip_forwarding ,
network_security_group = nsg
)
if self . dns_servers :
dns_settings = self . network_models . NetworkInterfaceDnsSettings (
dns_servers = self . dns_servers )
nic . dns_settings = dns_settings
self . results [ ' state ' ] = self . create_or_update_nic ( nic )
elif self . state == ' absent ' :
self . log ( ' Deleting network interface {0} ' . format ( self . name ) )