Support curated return value for network interface and refine test (#50482)
This commit is contained in:
parent
955e960f45
commit
eaf9da4dff
3 changed files with 377 additions and 380 deletions
|
@ -137,6 +137,9 @@ options:
|
|||
public_ip_address_name:
|
||||
description:
|
||||
- Name of the public ip address. None for disable ip address.
|
||||
aliases:
|
||||
- public_ip_address
|
||||
- public_ip_name
|
||||
public_ip_allocation_method:
|
||||
description:
|
||||
- public ip allocation method.
|
||||
|
|
|
@ -104,6 +104,95 @@ azure_networkinterfaces:
|
|||
"tags": {},
|
||||
"type": "Microsoft.Network/networkInterfaces"
|
||||
}]
|
||||
networkinterfaces:
|
||||
description: List of network interface dict, the dict contains parameters can be passed to C(azure_rm_networkinterface) module.
|
||||
type: list
|
||||
returned: always
|
||||
contains:
|
||||
id:
|
||||
description:
|
||||
- Id of the network interface.
|
||||
resource_group:
|
||||
description:
|
||||
- Name of a resource group where the network interface exists.
|
||||
name:
|
||||
description:
|
||||
- Name of the network interface.
|
||||
location:
|
||||
description:
|
||||
- Azure location.
|
||||
virtual_network:
|
||||
description:
|
||||
- An existing virtual network with which the network interface will be associated.
|
||||
- It is a dict which contains C(name) and C(resource_group) of the virtual network.
|
||||
subnet:
|
||||
description:
|
||||
- Name of an existing subnet within the specified virtual network.
|
||||
tags:
|
||||
description:
|
||||
- Tags of the network interface.
|
||||
ip_configurations:
|
||||
description:
|
||||
- List of ip configuration if contains mutilple configuration.
|
||||
contains:
|
||||
name:
|
||||
description:
|
||||
- Name of the ip configuration.
|
||||
private_ip_address:
|
||||
description:
|
||||
- Private ip address for the ip configuration.
|
||||
private_ip_allocation_method:
|
||||
description:
|
||||
- private ip allocation method.
|
||||
public_ip_address:
|
||||
description:
|
||||
- Name of the public ip address. None for disable ip address.
|
||||
public_ip_allocation_method:
|
||||
description:
|
||||
- public ip allocation method.
|
||||
load_balancer_backend_address_pools:
|
||||
description:
|
||||
- List of an existing load-balancer backend address pool id to associate with the network interface.
|
||||
primary:
|
||||
description:
|
||||
- Whether the ip configuration is the primary one in the list.
|
||||
enable_accelerated_networking:
|
||||
description:
|
||||
- Specifies whether the network interface should be created with the accelerated networking feature or not
|
||||
create_with_security_group:
|
||||
description:
|
||||
- Specifies whether a default security group should be be created with the NIC. Only applies when creating a new NIC.
|
||||
type: bool
|
||||
security_group:
|
||||
description:
|
||||
- A security group resource ID with which to associate the network interface.
|
||||
enable_ip_forwarding:
|
||||
description:
|
||||
- Whether to enable IP forwarding
|
||||
dns_servers:
|
||||
description:
|
||||
- Which DNS servers should the NIC lookup
|
||||
- List of IP's
|
||||
mac_address:
|
||||
description:
|
||||
- The MAC address of the network interface.
|
||||
provisioning_state:
|
||||
description:
|
||||
- The provisioning state of the network interface.
|
||||
dns_settings:
|
||||
description:
|
||||
- The DNS settings in network interface.
|
||||
contains:
|
||||
dns_servers:
|
||||
description: List of DNS servers IP addresses.
|
||||
applied_dns_servers:
|
||||
description:
|
||||
- If the VM that uses this NIC is part of an Availability Set, then this list will have the union of all DNS servers
|
||||
from all NICs that are part of the Availability Set. This property is what is configured on each of those VMs.
|
||||
internal_dns_name_label:
|
||||
description: Relative DNS name for this NIC used for internal communications between VMs in the same virtual network.
|
||||
internal_fqdn:
|
||||
description: Fully qualified DNS name supporting internal communications between VMs in the same virtual network.
|
||||
''' # NOQA
|
||||
try:
|
||||
from msrestazure.azure_exceptions import CloudError
|
||||
|
@ -112,12 +201,55 @@ except Exception:
|
|||
# This is handled in azure_rm_common
|
||||
pass
|
||||
|
||||
from ansible.module_utils.azure_rm_common import AzureRMModuleBase
|
||||
from ansible.module_utils.azure_rm_common import AzureRMModuleBase, azure_id_to_dict
|
||||
|
||||
|
||||
AZURE_OBJECT_CLASS = 'NetworkInterface'
|
||||
|
||||
|
||||
def nic_to_dict(nic):
|
||||
ip_configurations = [
|
||||
dict(
|
||||
name=config.name,
|
||||
private_ip_address=config.private_ip_address,
|
||||
private_ip_allocation_method=config.private_ip_allocation_method,
|
||||
primary=config.primary,
|
||||
load_balancer_backend_address_pools=([item.id for item in config.load_balancer_backend_address_pools]
|
||||
if config.load_balancer_backend_address_pools else None),
|
||||
public_ip_address=config.public_ip_address.id if config.public_ip_address else None,
|
||||
public_ip_allocation_method=config.public_ip_address.public_ip_allocation_method if config.public_ip_address else None
|
||||
) for config in nic.ip_configurations
|
||||
]
|
||||
config = nic.ip_configurations[0] if len(nic.ip_configurations) > 0 else None
|
||||
subnet_dict = azure_id_to_dict(config.subnet.id) if config and config.subnet else None
|
||||
subnet = subnet_dict.get('subnets') if subnet_dict else None
|
||||
virtual_network = dict(
|
||||
resource_group=subnet_dict.get('resourceGroups'),
|
||||
name=subnet_dict.get('virtualNetworks')) if subnet_dict else None
|
||||
return dict(
|
||||
id=nic.id,
|
||||
resource_group=azure_id_to_dict(nic.id).get('resourceGroups'),
|
||||
name=nic.name,
|
||||
subnet=subnet,
|
||||
virtual_network=virtual_network,
|
||||
location=nic.location,
|
||||
tags=nic.tags,
|
||||
security_group=nic.network_security_group.id if nic.network_security_group else None,
|
||||
dns_settings=dict(
|
||||
dns_servers=nic.dns_settings.dns_servers,
|
||||
applied_dns_servers=nic.dns_settings.applied_dns_servers,
|
||||
internal_dns_name_label=nic.dns_settings.internal_dns_name_label,
|
||||
internal_fqdn=nic.dns_settings.internal_fqdn
|
||||
),
|
||||
ip_configurations=ip_configurations,
|
||||
mac_address=nic.mac_address,
|
||||
enable_ip_forwarding=nic.enable_ip_forwarding,
|
||||
provisioning_state=nic.provisioning_state,
|
||||
enable_accelerated_networking=nic.enable_accelerated_networking,
|
||||
dns_servers=nic.dns_settings.dns_servers,
|
||||
)
|
||||
|
||||
|
||||
class AzureRMNetworkInterfaceFacts(AzureRMModuleBase):
|
||||
|
||||
def __init__(self):
|
||||
|
@ -150,57 +282,50 @@ class AzureRMNetworkInterfaceFacts(AzureRMModuleBase):
|
|||
if self.name and not self.resource_group:
|
||||
self.fail("Parameter error: resource group required when filtering by name.")
|
||||
|
||||
if self.name:
|
||||
self.results['ansible_facts']['azure_networkinterfaces'] = self.get_item()
|
||||
elif self.resource_group:
|
||||
self.results['ansible_facts']['azure_networkinterfaces'] = self.list_resource_group()
|
||||
else:
|
||||
self.results['ansible_facts']['azure_networkinterfaces'] = self.list_all()
|
||||
results = []
|
||||
|
||||
if self.name:
|
||||
results = self.get_item()
|
||||
elif self.resource_group:
|
||||
results = self.list_resource_group()
|
||||
else:
|
||||
results = self.list_all()
|
||||
|
||||
self.results['ansible_facts']['azure_networkinterfaces'] = self.serialize_nics(results)
|
||||
self.results['networkinterfaces'] = self.to_dict_list(results)
|
||||
return self.results
|
||||
|
||||
def get_item(self):
|
||||
self.log('Get properties for {0}'.format(self.name))
|
||||
result = []
|
||||
item = None
|
||||
try:
|
||||
item = self.network_client.network_interfaces.get(self.resource_group, self.name)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if item and self.has_tags(item.tags, self.tags):
|
||||
nic = self.serialize_obj(item, AZURE_OBJECT_CLASS)
|
||||
result = [nic]
|
||||
|
||||
return result
|
||||
return [item] if item and self.has_tags(item.tags, self.tags) else []
|
||||
|
||||
def list_resource_group(self):
|
||||
self.log('List for resource group')
|
||||
try:
|
||||
response = self.network_client.network_interfaces.list(self.resource_group)
|
||||
return [item for item in response if self.has_tags(item.tags, self.tags)]
|
||||
except Exception as exc:
|
||||
self.fail("Error listing by resource group {0} - {1}".format(self.resource_group, str(exc)))
|
||||
|
||||
results = []
|
||||
for item in response:
|
||||
if self.has_tags(item.tags, self.tags):
|
||||
nic = self.serialize_obj(item, AZURE_OBJECT_CLASS)
|
||||
results.append(nic)
|
||||
return results
|
||||
|
||||
def list_all(self):
|
||||
self.log('List all')
|
||||
try:
|
||||
response = self.network_client.network_interfaces.list_all()
|
||||
return [item for item in response if self.has_tags(item.tags, self.tags)]
|
||||
except Exception as exc:
|
||||
self.fail("Error listing all - {0}".format(str(exc)))
|
||||
|
||||
results = []
|
||||
for item in response:
|
||||
if self.has_tags(item.tags, self.tags):
|
||||
nic = self.serialize_obj(item, AZURE_OBJECT_CLASS)
|
||||
results.append(nic)
|
||||
return results
|
||||
def serialize_nics(self, raws):
|
||||
return [self.serialize_obj(item, AZURE_OBJECT_CLASS) for item in raws] if raws else []
|
||||
|
||||
def to_dict_list(self, raws):
|
||||
return [nic_to_dict(item) for item in raws] if raws else []
|
||||
|
||||
|
||||
def main():
|
||||
|
|
|
@ -51,379 +51,274 @@
|
|||
probe: prob0
|
||||
register: lb
|
||||
|
||||
- name: create public ip
|
||||
azure_rm_publicipaddress:
|
||||
name: "pip{{ rpfx }}"
|
||||
resource_group: '{{ resource_group }}'
|
||||
|
||||
- name: Create NIC (check mode)
|
||||
- name: Create most simple NIC with virtual_network id (check mode)
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}"
|
||||
virtual_network: "{{ vn.state.id }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
public_ip_name: "tn{{ rpfx }}"
|
||||
public_ip_allocation_method: Static
|
||||
security_group: "tn{{ rpfx }}"
|
||||
register: output
|
||||
check_mode: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.changed
|
||||
|
||||
- name: Create NIC using virtual_network resource_group parameter
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}rg"
|
||||
virtual_network:
|
||||
name: "tn{{ rpfx }}"
|
||||
resource_group: "{{ resource_group_secondary }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
public_ip_name: "tn{{ rpfx }}rg"
|
||||
public_ip_allocation_method: Static
|
||||
security_group: "tn{{ rpfx }}"
|
||||
register: output
|
||||
|
||||
- name: Create NIC using virtual_network resource_group parameter (idempotent)
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}rg"
|
||||
virtual_network:
|
||||
name: "tn{{ rpfx }}"
|
||||
resource_group: "{{ resource_group_secondary }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
public_ip_name: "tn{{ rpfx }}rg"
|
||||
public_ip_allocation_method: Static
|
||||
security_group: "tn{{ rpfx }}"
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- not output.changed
|
||||
|
||||
- name: Delete NIC
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}rg"
|
||||
state: absent
|
||||
|
||||
- name: Create NIC
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}"
|
||||
virtual_network: "{{ vn.state.id }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
public_ip_name: "tn{{ rpfx }}"
|
||||
public_ip_allocation_method: Static
|
||||
security_group:
|
||||
name: "tn{{ rpfx }}2"
|
||||
resource_group: "{{ resource_group_secondary }}"
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.changed
|
||||
- output.state.ip_configuration.subnet.name == 'tn{{ rpfx }}'
|
||||
|
||||
- name: Update the NIC with mutilple ip configurations (check mode)
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}"
|
||||
security_group:
|
||||
name: "tn{{ rpfx }}2"
|
||||
resource_group: "{{ resource_group_secondary }}"
|
||||
virtual_network: "{{ vn.state.id }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
ip_configurations:
|
||||
- name: ipconfig-add
|
||||
public_ip_name: "tn{{ rpfx }}2"
|
||||
- name: default
|
||||
public_ip_name: "tn{{ rpfx }}"
|
||||
primary: True
|
||||
public_ip_allocation_method: Static
|
||||
- name: ipconfig1
|
||||
public_ip_name: "tn{{ rpfx }}3"
|
||||
register: output
|
||||
check_mode: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.changed
|
||||
|
||||
- name: Update the NIC with mutilple ip configurations
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}"
|
||||
security_group:
|
||||
name: "tn{{ rpfx }}2"
|
||||
resource_group: "{{ resource_group_secondary }}"
|
||||
virtual_network: "{{ vn.state.id }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
ip_configurations:
|
||||
- name: ipconfig-add
|
||||
public_ip_name: "tn{{ rpfx }}2"
|
||||
- name: default
|
||||
public_ip_name: "tn{{ rpfx }}"
|
||||
primary: True
|
||||
public_ip_allocation_method: Static
|
||||
- name: ipconfig1
|
||||
public_ip_name: "tn{{ rpfx }}3"
|
||||
load_balancer_backend_address_pools:
|
||||
- "{{ lb.state.backend_address_pools[0].id }}"
|
||||
- name: backendaddrpool1
|
||||
load_balancer: "lb{{ rpfx }}"
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.changed
|
||||
- not output.state.ip_configuration
|
||||
- output.state.ip_configurations | length == 3
|
||||
- output.state.network_security_group.name == 'tn{{ rpfx }}2'
|
||||
|
||||
- name: Update the NIC with mutilple ip configurations (idempotent)
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}"
|
||||
security_group: "{{ output.state.network_security_group.id }}"
|
||||
virtual_network: "{{ vn.state.id }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
ip_configurations:
|
||||
- name: ipconfig-add
|
||||
public_ip_name: "tn{{ rpfx }}2"
|
||||
- name: default
|
||||
public_ip_name: "tn{{ rpfx }}"
|
||||
primary: True
|
||||
public_ip_allocation_method: Static
|
||||
- name: ipconfig1
|
||||
public_ip_name: "tn{{ rpfx }}3"
|
||||
load_balancer_backend_address_pools:
|
||||
- "{{ lb.state.backend_address_pools[0].id }}"
|
||||
- name: backendaddrpool1
|
||||
load_balancer: "lb{{ rpfx }}"
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- not output.changed
|
||||
|
||||
- name: Remove one ip configuration
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}"
|
||||
security_group:
|
||||
name: "tn{{ rpfx }}2"
|
||||
resource_group: "{{ resource_group_secondary }}"
|
||||
virtual_network: "{{ vn.state.id }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
ip_configurations:
|
||||
- name: ipconfig1
|
||||
public_ip_name: "tn{{ rpfx }}3"
|
||||
load_balancer_backend_address_pools:
|
||||
- "{{ lb.state.backend_address_pools[0].id }}"
|
||||
- name: backendaddrpool1
|
||||
load_balancer: "lb{{ rpfx }}"
|
||||
- name: default
|
||||
public_ip_name: "tn{{ rpfx }}"
|
||||
public_ip_allocation_method: Static
|
||||
primary: True
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- not output.state.ip_configuration
|
||||
- output.state.ip_configurations | length == 2
|
||||
|
||||
- name: IP configuration without public IP and NSG
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}noip"
|
||||
public_ip: False
|
||||
create_with_security_group: False
|
||||
virtual_network: "{{ vn.state.id }}"
|
||||
register: output
|
||||
check_mode: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.changed
|
||||
|
||||
- name: Create most simple NIC with virtual_network resource_group
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}"
|
||||
virtual_network:
|
||||
name: "tn{{ rpfx }}"
|
||||
resource_group: "{{ resource_group_secondary }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
public_ip: False
|
||||
create_with_security_group: False
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.changed
|
||||
- output.state.id
|
||||
|
||||
- name: Get fact of the new created NIC
|
||||
azure_rm_networkinterface_facts:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}"
|
||||
register: facts
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "facts.networkinterfaces | length == 1"
|
||||
- facts.networkinterfaces[0].id == output.state.id
|
||||
- "facts.networkinterfaces[0].ip_configurations | length == 1"
|
||||
- not facts.networkinterfaces[0].security_group
|
||||
- not facts.networkinterfaces[0].ip_configurations[0].public_ip_address
|
||||
- not facts.networkinterfaces[0].enable_ip_forwarding
|
||||
- not facts.networkinterfaces[0].enable_accelerated_networking
|
||||
|
||||
- name: Create most simple NIC with ip configurations (idempotent)
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ facts.networkinterfaces[0].resource_group }}"
|
||||
name: "{{ facts.networkinterfaces[0].name }}"
|
||||
virtual_network: "{{ facts.networkinterfaces[0].virtual_network }}"
|
||||
create_with_security_group: False
|
||||
ip_configurations:
|
||||
- name: ipconfig1
|
||||
primary: True
|
||||
- name: "{{ facts.networkinterfaces[0].ip_configurations[0].name }}"
|
||||
private_ip_address: "{{ facts.networkinterfaces[0].ip_configurations[0].private_ip_address }}"
|
||||
private_ip_allocation_method: "{{ facts.networkinterfaces[0].ip_configurations[0].private_ip_allocation_method }}"
|
||||
primary: "{{ facts.networkinterfaces[0].ip_configurations[0].primary }}"
|
||||
subnet: "{{ facts.networkinterfaces[0].subnet }}"
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.state.ip_configurations[0].public_ip_address == None
|
||||
- output.state.network_security_group == None
|
||||
- not output.changed
|
||||
|
||||
- name: NIC with Accelerated networking enabled
|
||||
- name: Create most simple NIC (idempotent)
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}an"
|
||||
name: "tn{{ rpfx }}"
|
||||
virtual_network: "{{ vn.state.id }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
create_with_security_group: False
|
||||
public_ip: False
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- not output.changed
|
||||
|
||||
- name: Update security group (check mode)
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}"
|
||||
virtual_network: "{{ vn.state.id }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
public_ip: False
|
||||
security_group: "tn{{ rpfx }}sg"
|
||||
register: output
|
||||
check_mode: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.changed
|
||||
|
||||
- name: Update public ip address (check mode)
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}"
|
||||
virtual_network: "{{ vn.state.id }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
public_ip_address_name: "tn{{ rpfx }}"
|
||||
create_with_security_group: False
|
||||
register: output
|
||||
check_mode: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.changed
|
||||
|
||||
- name: Update accelerated networking (check mode)
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}"
|
||||
virtual_network: "{{ vn.state.id }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
enable_accelerated_networking: True
|
||||
create_with_security_group: False
|
||||
public_ip: False
|
||||
register: output
|
||||
check_mode: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.state.enable_accelerated_networking
|
||||
- output.changed
|
||||
|
||||
- name: NIC with Accelerated networking enabled (check idempotent)
|
||||
- name: Update IP forwarding networking (check mode)
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}an"
|
||||
name: "tn{{ rpfx }}"
|
||||
virtual_network: "{{ vn.state.id }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
enable_accelerated_networking: True
|
||||
create_with_security_group: False
|
||||
enable_ip_forwarding: True
|
||||
public_ip: False
|
||||
register: output
|
||||
check_mode: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.state.enable_accelerated_networking
|
||||
- not output.changed
|
||||
- output.changed
|
||||
|
||||
- name: Disable (previously enabled) Accelerated networking
|
||||
- name: Update dns server (check mode)
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}an"
|
||||
virtual_network: "{{ vn.state.id }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
enable_accelerated_networking: False
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- not output.state.enable_accelerated_networking
|
||||
- output.changed
|
||||
|
||||
- name: Delete AN NIC
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}an"
|
||||
state: absent
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.changed
|
||||
|
||||
- name: NIC with IP forwarding networking enabled
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}ipf"
|
||||
virtual_network: "{{ vn.state.id }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
enable_ip_forwarding: True
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.state.enable_ip_forwarding
|
||||
- output.changed
|
||||
|
||||
- name: NIC with IP forwarding enabled (check idempotent)
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}ipf"
|
||||
virtual_network: "{{ vn.state.id }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
enable_ip_forwarding: True
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.state.enable_ip_forwarding
|
||||
- not output.changed
|
||||
|
||||
- name: Disable (previously enabled) IP forwarding
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}ipf"
|
||||
virtual_network: "{{ vn.state.id }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
enable_ip_forwarding: False
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- not output.state.enable_ip_forwarding
|
||||
- output.changed
|
||||
|
||||
- name: Delete IP forwarding NIC
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}ipf"
|
||||
state: absent
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.changed
|
||||
|
||||
- name: NIC with dns servers
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}dns"
|
||||
name: "tn{{ rpfx }}"
|
||||
virtual_network: "{{ vn.state.id }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
create_with_security_group: False
|
||||
public_ip: False
|
||||
dns_servers:
|
||||
- 8.9.10.11
|
||||
- 7.8.9.10
|
||||
register: output
|
||||
check_mode: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.changed
|
||||
|
||||
- name: Update NIC
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}"
|
||||
virtual_network: "{{ vn.state.id }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
enable_accelerated_networking: True
|
||||
enable_ip_forwarding: True
|
||||
security_group: "tn{{ rpfx }}sg"
|
||||
dns_servers:
|
||||
- 8.9.10.11
|
||||
- 7.8.9.10
|
||||
ip_configurations:
|
||||
- name: "{{ facts.networkinterfaces[0].ip_configurations[0].name }}"
|
||||
private_ip_address: "{{ facts.networkinterfaces[0].ip_configurations[0].private_ip_address }}"
|
||||
private_ip_allocation_method: "{{ facts.networkinterfaces[0].ip_configurations[0].private_ip_allocation_method }}"
|
||||
primary: "{{ facts.networkinterfaces[0].ip_configurations[0].primary }}"
|
||||
- name: ipconfig1
|
||||
public_ip_name: "tn{{ rpfx }}"
|
||||
load_balancer_backend_address_pools:
|
||||
- "{{ lb.state.backend_address_pools[0].id }}"
|
||||
- name: backendaddrpool1
|
||||
load_balancer: "lb{{ rpfx }}"
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.changed
|
||||
- output.state.dns_settings.dns_servers == ['8.9.10.11', '7.8.9.10']
|
||||
- output.state.enable_ip_forwarding
|
||||
- output.state.network_security_group.name == "tn{{ rpfx }}sg"
|
||||
- output.state.enable_accelerated_networking
|
||||
|
||||
- name: Complicated NIC (idempontent)
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}"
|
||||
virtual_network: "{{ vn.state.id }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
enable_accelerated_networking: True
|
||||
security_group: "tn{{ rpfx }}sg"
|
||||
enable_ip_forwarding: True
|
||||
dns_servers:
|
||||
- 8.9.10.11
|
||||
- 7.8.9.10
|
||||
ip_configurations:
|
||||
- name: "{{ facts.networkinterfaces[0].ip_configurations[0].name }}"
|
||||
private_ip_address: "{{ facts.networkinterfaces[0].ip_configurations[0].private_ip_address }}"
|
||||
private_ip_allocation_method: "{{ facts.networkinterfaces[0].ip_configurations[0].private_ip_allocation_method }}"
|
||||
primary: "{{ facts.networkinterfaces[0].ip_configurations[0].primary }}"
|
||||
- name: ipconfig1
|
||||
public_ip_name: "tn{{ rpfx }}"
|
||||
load_balancer_backend_address_pools:
|
||||
- "{{ lb.state.backend_address_pools[0].id }}"
|
||||
- name: backendaddrpool1
|
||||
load_balancer: "lb{{ rpfx }}"
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- not output.changed
|
||||
|
||||
- name: Get fact of the new created NIC
|
||||
azure_rm_networkinterface_facts:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}"
|
||||
register: facts
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "facts.networkinterfaces | length == 1"
|
||||
- facts.networkinterfaces[0].id == output.state.id
|
||||
- "facts.networkinterfaces[0].ip_configurations | length == 2"
|
||||
- 'facts.networkinterfaces[0].security_group.endswith("tn{{ rpfx }}sg")'
|
||||
- facts.networkinterfaces[0].enable_accelerated_networking
|
||||
- facts.networkinterfaces[0].enable_ip_forwarding
|
||||
|
||||
- name: Remove one dns server and ip configuration
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "tn{{ rpfx }}"
|
||||
virtual_network: "{{ vn.state.id }}"
|
||||
subnet: "tn{{ rpfx }}"
|
||||
security_group: "tn{{ rpfx }}sg"
|
||||
enable_accelerated_networking: True
|
||||
enable_ip_forwarding: True
|
||||
dns_servers:
|
||||
- 8.9.10.11
|
||||
ip_configurations:
|
||||
- name: ipconfig1
|
||||
public_ip_name: "tn{{ rpfx }}"
|
||||
primary: True
|
||||
load_balancer_backend_address_pools:
|
||||
- "{{ lb.state.backend_address_pools[0].id }}"
|
||||
- name: backendaddrpool1
|
||||
load_balancer: "lb{{ rpfx }}"
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.changed
|
||||
- output.state.dns_settings.dns_servers == ['8.9.10.11']
|
||||
- output.state.enable_ip_forwarding
|
||||
- output.state.network_security_group.name == "tn{{ rpfx }}sg"
|
||||
- "output.state.ip_configurations | length == 1"
|
||||
- output.state.ip_configurations[0].public_ip_address.name == "tn{{ rpfx }}"
|
||||
- output.state.enable_accelerated_networking
|
||||
|
||||
- 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 }}"
|
||||
|
@ -439,11 +334,8 @@
|
|||
- name: Delete the NIC
|
||||
azure_rm_networkinterface:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "{{ item }}"
|
||||
name: "tn{{ rpfx }}"
|
||||
state: absent
|
||||
with_items:
|
||||
- "tn{{ rpfx }}"
|
||||
- "tn{{ rpfx }}noip"
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
|
@ -465,29 +357,6 @@
|
|||
azure_rm_loadbalancer:
|
||||
resource_group: '{{ resource_group }}'
|
||||
name: "lb{{ rpfx }}"
|
||||
frontend_ip_configurations:
|
||||
- name: frontendipconf0
|
||||
public_ip_address: "pip{{ rpfx }}"
|
||||
backend_address_pools:
|
||||
- name: backendaddrpool0
|
||||
- name: backendaddrpool1
|
||||
probes:
|
||||
- name: prob0
|
||||
port: 80
|
||||
inbound_nat_pools:
|
||||
- name: inboundnatpool0
|
||||
frontend_ip_configuration_name: frontendipconf0
|
||||
protocol: Tcp
|
||||
frontend_port_range_start: 80
|
||||
frontend_port_range_end: 81
|
||||
backend_port: 8080
|
||||
load_balancing_rules:
|
||||
- name: lbrbalancingrule0
|
||||
frontend_ip_configuration: frontendipconf0
|
||||
backend_address_pool: backendaddrpool0
|
||||
frontend_port: 80
|
||||
backend_port: 80
|
||||
probe: prob0
|
||||
state: absent
|
||||
|
||||
- name: delete public ip
|
||||
|
|
Loading…
Reference in a new issue