mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
* create internal loadbalancer * fix test * remove duplicate test * clean up * fix doc * lint * add sku support * update version * change to the version the same as CLI * add pip support sku * fix lint * fix test * Update main.yml * add changelog entry
This commit is contained in:
parent
17a4553c68
commit
9348809184
5 changed files with 151 additions and 19 deletions
3
changelogs/fragments/azure-lb-sku.yaml
Normal file
3
changelogs/fragments/azure-lb-sku.yaml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
minor_changes:
|
||||||
|
- azure_rm_loadbalancer - add support for sku
|
||||||
|
- azure_rm_publicipaddress - add support for sku
|
|
@ -933,13 +933,13 @@ class AzureRMModuleBase(object):
|
||||||
if not self._network_client:
|
if not self._network_client:
|
||||||
self._network_client = self.get_mgmt_svc_client(NetworkManagementClient,
|
self._network_client = self.get_mgmt_svc_client(NetworkManagementClient,
|
||||||
base_url=self._cloud_environment.endpoints.resource_manager,
|
base_url=self._cloud_environment.endpoints.resource_manager,
|
||||||
api_version='2017-06-01')
|
api_version='2017-11-01')
|
||||||
return self._network_client
|
return self._network_client
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def network_models(self):
|
def network_models(self):
|
||||||
self.log("Getting network models...")
|
self.log("Getting network models...")
|
||||||
return NetworkManagementClient.models("2017-06-01")
|
return NetworkManagementClient.models("2017-11-01")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rm_client(self):
|
def rm_client(self):
|
||||||
|
|
|
@ -43,6 +43,13 @@ options:
|
||||||
description:
|
description:
|
||||||
- Valid azure location. Defaults to location of the resource group.
|
- Valid azure location. Defaults to location of the resource group.
|
||||||
default: resource_group location
|
default: resource_group location
|
||||||
|
sku:
|
||||||
|
description:
|
||||||
|
The load balancer SKU.
|
||||||
|
choices:
|
||||||
|
- Basic
|
||||||
|
- Standard
|
||||||
|
version_added: 2.6
|
||||||
frontend_ip_configurations:
|
frontend_ip_configurations:
|
||||||
description: List of frontend IPs to be used
|
description: List of frontend IPs to be used
|
||||||
suboptions:
|
suboptions:
|
||||||
|
@ -51,7 +58,20 @@ options:
|
||||||
required: True
|
required: True
|
||||||
public_ip_address:
|
public_ip_address:
|
||||||
description: Name of an existing public IP address object in the current resource group to associate with the security group.
|
description: Name of an existing public IP address object in the current resource group to associate with the security group.
|
||||||
required: True
|
private_ip_address:
|
||||||
|
description: The reference of the Public IP resource.
|
||||||
|
version_added: 2.6
|
||||||
|
private_ip_allocation_method:
|
||||||
|
description: The Private IP allocation method.
|
||||||
|
choices:
|
||||||
|
- Static
|
||||||
|
- Dynamic
|
||||||
|
version_added: 2.6
|
||||||
|
subnet:
|
||||||
|
description:
|
||||||
|
- The reference of the subnet resource.
|
||||||
|
- Should be an existing subnet's resource id.
|
||||||
|
version_added: 2.6
|
||||||
version_added: 2.5
|
version_added: 2.5
|
||||||
backend_address_pools:
|
backend_address_pools:
|
||||||
description: List of backend address pools
|
description: List of backend address pools
|
||||||
|
@ -321,7 +341,7 @@ changed:
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import random
|
import random
|
||||||
from ansible.module_utils.azure_rm_common import AzureRMModuleBase
|
from ansible.module_utils.azure_rm_common import AzureRMModuleBase, format_resource_id
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from msrestazure.tools import parse_resource_id
|
from msrestazure.tools import parse_resource_id
|
||||||
|
@ -337,8 +357,16 @@ frontend_ip_configuration_spec = dict(
|
||||||
required=True
|
required=True
|
||||||
),
|
),
|
||||||
public_ip_address=dict(
|
public_ip_address=dict(
|
||||||
type='str',
|
type='str'
|
||||||
required=True
|
),
|
||||||
|
private_ip_address=dict(
|
||||||
|
type='str'
|
||||||
|
),
|
||||||
|
private_ip_allocation_method=dict(
|
||||||
|
type='str'
|
||||||
|
),
|
||||||
|
subnet=dict(
|
||||||
|
type='str'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -474,6 +502,10 @@ class AzureRMLoadBalancer(AzureRMModuleBase):
|
||||||
location=dict(
|
location=dict(
|
||||||
type='str'
|
type='str'
|
||||||
),
|
),
|
||||||
|
sku=dict(
|
||||||
|
type='str',
|
||||||
|
choices=['Basic', 'Standard']
|
||||||
|
),
|
||||||
frontend_ip_configurations=dict(
|
frontend_ip_configurations=dict(
|
||||||
type='list',
|
type='list',
|
||||||
elements='dict',
|
elements='dict',
|
||||||
|
@ -556,6 +588,7 @@ class AzureRMLoadBalancer(AzureRMModuleBase):
|
||||||
self.resource_group = None
|
self.resource_group = None
|
||||||
self.name = None
|
self.name = None
|
||||||
self.location = None
|
self.location = None
|
||||||
|
self.sku = None
|
||||||
self.frontend_ip_configurations = None
|
self.frontend_ip_configurations = None
|
||||||
self.backend_address_pools = None
|
self.backend_address_pools = None
|
||||||
self.probes = None
|
self.probes = None
|
||||||
|
@ -658,7 +691,10 @@ class AzureRMLoadBalancer(AzureRMModuleBase):
|
||||||
# create or update
|
# create or update
|
||||||
frontend_ip_configurations_param = [self.network_models.FrontendIPConfiguration(
|
frontend_ip_configurations_param = [self.network_models.FrontendIPConfiguration(
|
||||||
name=item.get('name'),
|
name=item.get('name'),
|
||||||
public_ip_address=self.get_public_ip_address(item.get('public_ip_address'))
|
public_ip_address=self.get_public_ip_address_instance(item.get('public_ip_address')) if item.get('public_ip_address') else None,
|
||||||
|
private_ip_address=item.get('private_ip_address'),
|
||||||
|
private_ip_allocation_method=item.get('private_ip_allocation_method'),
|
||||||
|
subnet=self.network_models.Subnet(id=item.get('subnet')) if item.get('subnet') else None
|
||||||
) for item in self.frontend_ip_configurations] if self.frontend_ip_configurations else None
|
) for item in self.frontend_ip_configurations] if self.frontend_ip_configurations else None
|
||||||
|
|
||||||
backend_address_pools_param = [self.network_models.BackendAddressPool(
|
backend_address_pools_param = [self.network_models.BackendAddressPool(
|
||||||
|
@ -723,6 +759,7 @@ class AzureRMLoadBalancer(AzureRMModuleBase):
|
||||||
) for item in self.load_balancing_rules] if self.load_balancing_rules else None
|
) for item in self.load_balancing_rules] if self.load_balancing_rules else None
|
||||||
|
|
||||||
param = self.network_models.LoadBalancer(
|
param = self.network_models.LoadBalancer(
|
||||||
|
sku=self.network_models.LoadBalancerSku(self.sku) if self.sku else None,
|
||||||
location=self.location,
|
location=self.location,
|
||||||
frontend_ip_configurations=frontend_ip_configurations_param,
|
frontend_ip_configurations=frontend_ip_configurations_param,
|
||||||
backend_address_pools=backend_address_pools_param,
|
backend_address_pools=backend_address_pools_param,
|
||||||
|
@ -738,16 +775,11 @@ class AzureRMLoadBalancer(AzureRMModuleBase):
|
||||||
|
|
||||||
return self.results
|
return self.results
|
||||||
|
|
||||||
def get_public_ip_address(self, id):
|
def get_public_ip_address_instance(self, id):
|
||||||
"""Get a reference to the public ip address resource"""
|
"""Get a reference to the public ip address resource"""
|
||||||
self.log('Fetching public ip address {}'.format(id))
|
self.log('Fetching public ip address {}'.format(id))
|
||||||
pip_dict = parse_resource_id(id)
|
resource_id = format_resource_id(id, self.subscription_id, 'Microsoft.Network', 'publicIPAddresses', self.resource_group)
|
||||||
resource_group = pip_dict.get('resource_group', self.resource_group)
|
return self.network_models.PublicIPAddress(id=resource_id)
|
||||||
name = pip_dict.get('name')
|
|
||||||
try:
|
|
||||||
return self.network_client.public_ip_addresses.get(resource_group, name)
|
|
||||||
except CloudError as err:
|
|
||||||
self.fail('Error fetching public ip address {} - {}'.format(name, str(err)))
|
|
||||||
|
|
||||||
def get_load_balancer(self):
|
def get_load_balancer(self):
|
||||||
"""Get a load balancer"""
|
"""Get a load balancer"""
|
||||||
|
@ -784,6 +816,7 @@ def load_balancer_to_dict(load_balancer):
|
||||||
id=load_balancer.id,
|
id=load_balancer.id,
|
||||||
name=load_balancer.name,
|
name=load_balancer.name,
|
||||||
location=load_balancer.location,
|
location=load_balancer.location,
|
||||||
|
sku=load_balancer.sku.name,
|
||||||
tags=load_balancer.tags,
|
tags=load_balancer.tags,
|
||||||
provisioning_state=load_balancer.provisioning_state,
|
provisioning_state=load_balancer.provisioning_state,
|
||||||
etag=load_balancer.etag,
|
etag=load_balancer.etag,
|
||||||
|
|
|
@ -61,6 +61,13 @@ options:
|
||||||
description:
|
description:
|
||||||
- Valid azure location. Defaults to location of the resource group.
|
- Valid azure location. Defaults to location of the resource group.
|
||||||
default: resource_group location
|
default: resource_group location
|
||||||
|
sku:
|
||||||
|
description:
|
||||||
|
- The public IP address SKU.
|
||||||
|
choices:
|
||||||
|
- Basic
|
||||||
|
- Standard
|
||||||
|
version_added: 2.6
|
||||||
|
|
||||||
extends_documentation_fragment:
|
extends_documentation_fragment:
|
||||||
- azure
|
- azure
|
||||||
|
@ -125,7 +132,8 @@ def pip_to_dict(pip):
|
||||||
ip_address=pip.ip_address,
|
ip_address=pip.ip_address,
|
||||||
idle_timeout_in_minutes=pip.idle_timeout_in_minutes,
|
idle_timeout_in_minutes=pip.idle_timeout_in_minutes,
|
||||||
provisioning_state=pip.provisioning_state,
|
provisioning_state=pip.provisioning_state,
|
||||||
etag=pip.etag
|
etag=pip.etag,
|
||||||
|
sku=pip.sku.name
|
||||||
)
|
)
|
||||||
if pip.dns_settings:
|
if pip.dns_settings:
|
||||||
result['dns_settings']['domain_name_label'] = pip.dns_settings.domain_name_label
|
result['dns_settings']['domain_name_label'] = pip.dns_settings.domain_name_label
|
||||||
|
@ -145,6 +153,7 @@ class AzureRMPublicIPAddress(AzureRMModuleBase):
|
||||||
location=dict(type='str'),
|
location=dict(type='str'),
|
||||||
allocation_method=dict(type='str', default='Dynamic', choices=['Dynamic', 'Static']),
|
allocation_method=dict(type='str', default='Dynamic', choices=['Dynamic', 'Static']),
|
||||||
domain_name=dict(type='str', aliases=['domain_name_label']),
|
domain_name=dict(type='str', aliases=['domain_name_label']),
|
||||||
|
sku=dict(type='str', choices=['Basic', 'Standard'])
|
||||||
)
|
)
|
||||||
|
|
||||||
self.resource_group = None
|
self.resource_group = None
|
||||||
|
@ -154,6 +163,7 @@ class AzureRMPublicIPAddress(AzureRMModuleBase):
|
||||||
self.tags = None
|
self.tags = None
|
||||||
self.allocation_method = None
|
self.allocation_method = None
|
||||||
self.domain_name = None
|
self.domain_name = None
|
||||||
|
self.sku = None
|
||||||
|
|
||||||
self.results = dict(
|
self.results = dict(
|
||||||
changed=False,
|
changed=False,
|
||||||
|
@ -194,6 +204,11 @@ class AzureRMPublicIPAddress(AzureRMModuleBase):
|
||||||
changed = True
|
changed = True
|
||||||
results['public_ip_allocation_method'] = self.allocation_method
|
results['public_ip_allocation_method'] = self.allocation_method
|
||||||
|
|
||||||
|
if self.sku and self.sku != results['sku']:
|
||||||
|
self.log("CHANGED: sku")
|
||||||
|
changed = True
|
||||||
|
results['sku'] = self.sku
|
||||||
|
|
||||||
update_tags, results['tags'] = self.update_tags(results['tags'])
|
update_tags, results['tags'] = self.update_tags(results['tags'])
|
||||||
if update_tags:
|
if update_tags:
|
||||||
changed = True
|
changed = True
|
||||||
|
@ -220,6 +235,7 @@ class AzureRMPublicIPAddress(AzureRMModuleBase):
|
||||||
pip = self.network_models.PublicIPAddress(
|
pip = self.network_models.PublicIPAddress(
|
||||||
location=self.location,
|
location=self.location,
|
||||||
public_ip_allocation_method=self.allocation_method,
|
public_ip_allocation_method=self.allocation_method,
|
||||||
|
sku=self.network_models.PublicIPAddressSku(name=self.sku) if self.sku else None
|
||||||
)
|
)
|
||||||
if self.tags:
|
if self.tags:
|
||||||
pip.tags = self.tags
|
pip.tags = self.tags
|
||||||
|
|
|
@ -1,3 +1,10 @@
|
||||||
|
- name: create public ip
|
||||||
|
azure_rm_publicipaddress:
|
||||||
|
name: ansiblepipstandard
|
||||||
|
sku: Standard
|
||||||
|
allocation_method: Static
|
||||||
|
resource_group: '{{ resource_group }}'
|
||||||
|
|
||||||
- name: create public ip
|
- name: create public ip
|
||||||
azure_rm_publicipaddress:
|
azure_rm_publicipaddress:
|
||||||
name: ansiblepip3
|
name: ansiblepip3
|
||||||
|
@ -46,7 +53,8 @@
|
||||||
azure_rm_loadbalancer:
|
azure_rm_loadbalancer:
|
||||||
resource_group: '{{ resource_group }}'
|
resource_group: '{{ resource_group }}'
|
||||||
name: lbtestfromansible
|
name: lbtestfromansible
|
||||||
public_ip_address: ansiblepip3
|
sku: Standard
|
||||||
|
public_ip_address: ansiblepipstandard
|
||||||
probe_protocol: Tcp
|
probe_protocol: Tcp
|
||||||
probe_port: 80
|
probe_port: 80
|
||||||
probe_interval: 10
|
probe_interval: 10
|
||||||
|
@ -64,7 +72,9 @@
|
||||||
|
|
||||||
- name: assert complex load balancer created
|
- name: assert complex load balancer created
|
||||||
assert:
|
assert:
|
||||||
that: output.changed
|
that:
|
||||||
|
- output.changed
|
||||||
|
- output.state.sku == 'Standard'
|
||||||
|
|
||||||
- name: delete load balancer
|
- name: delete load balancer
|
||||||
azure_rm_loadbalancer:
|
azure_rm_loadbalancer:
|
||||||
|
@ -110,8 +120,78 @@
|
||||||
name: lbtestfromansible
|
name: lbtestfromansible
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
|
- name: Create virtual network
|
||||||
|
azure_rm_virtualnetwork:
|
||||||
|
resource_group: "{{ resource_group }}"
|
||||||
|
name: lbtestfromansiblevn
|
||||||
|
address_prefixes: "10.10.0.0/16"
|
||||||
|
|
||||||
|
- name: Add subnet
|
||||||
|
azure_rm_subnet:
|
||||||
|
resource_group: "{{ resource_group }}"
|
||||||
|
name: lbtestfromansiblesb
|
||||||
|
address_prefix: "10.10.0.0/24"
|
||||||
|
virtual_network: lbtestfromansiblevn
|
||||||
|
register: subnet
|
||||||
|
|
||||||
|
- name: create internal loadbalancer
|
||||||
|
azure_rm_loadbalancer:
|
||||||
|
resource_group: '{{ resource_group }}'
|
||||||
|
name: lbtestfromansible
|
||||||
|
frontend_ip_configurations:
|
||||||
|
- name: frontendipconf0
|
||||||
|
private_ip_address: 10.10.0.10
|
||||||
|
private_ip_allocation_method: Static
|
||||||
|
subnet: "{{ subnet.state.id }}"
|
||||||
|
backend_address_pools:
|
||||||
|
- name: backendaddrpool0
|
||||||
|
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
|
||||||
|
register: output
|
||||||
|
|
||||||
|
- name: assert complex load balancer created
|
||||||
|
assert:
|
||||||
|
that: output.changed
|
||||||
|
|
||||||
|
- name: delete load balancer
|
||||||
|
azure_rm_loadbalancer:
|
||||||
|
resource_group: '{{ resource_group }}'
|
||||||
|
name: lbtestfromansible
|
||||||
|
state: absent
|
||||||
|
|
||||||
- name: cleanup public ip
|
- name: cleanup public ip
|
||||||
azure_rm_publicipaddress:
|
azure_rm_publicipaddress:
|
||||||
name: ansiblepip3
|
name: "{{ item }}"
|
||||||
resource_group: '{{ resource_group }}'
|
resource_group: '{{ resource_group }}'
|
||||||
state: absent
|
state: absent
|
||||||
|
with_items:
|
||||||
|
- ansiblepip3
|
||||||
|
- ansiblepipstandard
|
||||||
|
|
||||||
|
- name: cleanup subnet
|
||||||
|
azure_rm_subnet:
|
||||||
|
resource_group: "{{ resource_group }}"
|
||||||
|
name: lbtestfromansiblesb
|
||||||
|
virtual_network: lbtestfromansiblevn
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- name: cleanup virtual network
|
||||||
|
azure_rm_virtualnetwork:
|
||||||
|
resource_group: "{{ resource_group }}"
|
||||||
|
name: lbtestfromansiblevn
|
||||||
|
state: absent
|
||||||
|
|
Loading…
Reference in a new issue