mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
azure_rm_networkinterface: Feature/dns servers (#43588)
* Working through tests and fixing dumb mistakes * Fix sanity issues and tests. All G * Correct type test for azure_rm_networkinterface * azure_rm_networkinterface correct type comparison * Post rebase cleanup * Remove erroneous reference to dns_servers
This commit is contained in:
parent
0972d37872
commit
56ea56f2b5
2 changed files with 98 additions and 0 deletions
|
@ -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))
|
||||
|
|
|
@ -358,6 +358,72 @@
|
|||
that:
|
||||
- output.changed
|
||||
|
||||
- name: NIC with dns servers
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}dns"
|
||||
virtual_network: "{{ vn.state.id }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
dns_servers:
|
||||
- 8.9.10.11
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.changed
|
||||
- output.state.dns_settings.dns_servers == ['8.9.10.11']
|
||||
|
||||
- name: NIC with dns servers is idempotent
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}dns"
|
||||
virtual_network: "{{ vn.state.id }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
dns_servers:
|
||||
- 8.9.10.11
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- not output.changed
|
||||
|
||||
- name: NIC with dns servers adding server
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}dns"
|
||||
virtual_network: "{{ vn.state.id }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
dns_servers:
|
||||
- 8.9.10.11
|
||||
- 10.11.12.13
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.changed
|
||||
- output.state.dns_settings.dns_servers | sort() == ['8.9.10.11', '10.11.12.13'] | sort()
|
||||
|
||||
- name: NIC with dns servers removing server
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}dns"
|
||||
virtual_network: "{{ vn.state.id }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
dns_servers:
|
||||
- 10.11.12.13
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.changed
|
||||
- output.state.dns_settings.dns_servers == ['10.11.12.13']
|
||||
|
||||
- name: Delete DNS servers NIC
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}dns"
|
||||
state: absent
|
||||
|
||||
- name: Delete the NIC (check mode)
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
|
|
Loading…
Reference in a new issue