mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
azure_rm_virtualmachine: adding possibility of disabling public ip address (#36766)
* adding possibility of disabling public ip address * fixed indent * fixed whitespace * fixed mistake * try to create test with vm without public ip address * try to fix test * another attempt for test * fixing test * create vm with no ip with different name and delete it immediately * a few additional fixes * another attempt to pass test * must be deleted * simplified no ip test * reorganised tests * Wrapped choice in C()
This commit is contained in:
parent
89a80e0591
commit
0b828ee830
2 changed files with 38 additions and 6 deletions
|
@ -202,9 +202,11 @@ options:
|
||||||
- If a public IP address is created when creating the VM (because a Network Interface was not provided),
|
- If a public IP address is created when creating the VM (because a Network Interface was not provided),
|
||||||
determines if the public IP address remains permanently associated with the Network Interface. If set
|
determines if the public IP address remains permanently associated with the Network Interface. If set
|
||||||
to 'Dynamic' the public IP address may change any time the VM is rebooted or power cycled.
|
to 'Dynamic' the public IP address may change any time the VM is rebooted or power cycled.
|
||||||
|
- The C(Disabled) choice was added in Ansible 2.6.
|
||||||
choices:
|
choices:
|
||||||
- Dynamic
|
- Dynamic
|
||||||
- Static
|
- Static
|
||||||
|
- Disabled
|
||||||
default:
|
default:
|
||||||
- Static
|
- Static
|
||||||
aliases:
|
aliases:
|
||||||
|
@ -646,7 +648,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
||||||
default='ReadOnly'),
|
default='ReadOnly'),
|
||||||
managed_disk_type=dict(type='str', choices=['Standard_LRS', 'Premium_LRS']),
|
managed_disk_type=dict(type='str', choices=['Standard_LRS', 'Premium_LRS']),
|
||||||
os_type=dict(type='str', choices=['Linux', 'Windows'], default='Linux'),
|
os_type=dict(type='str', choices=['Linux', 'Windows'], default='Linux'),
|
||||||
public_ip_allocation_method=dict(type='str', choices=['Dynamic', 'Static'], default='Static',
|
public_ip_allocation_method=dict(type='str', choices=['Dynamic', 'Static', 'Disabled'], default='Static',
|
||||||
aliases=['public_ip_allocation']),
|
aliases=['public_ip_allocation']),
|
||||||
open_ports=dict(type='list'),
|
open_ports=dict(type='list'),
|
||||||
network_interface_names=dict(type='list', aliases=['network_interfaces']),
|
network_interface_names=dict(type='list', aliases=['network_interfaces']),
|
||||||
|
@ -1641,8 +1643,11 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
||||||
if not subnet_id:
|
if not subnet_id:
|
||||||
self.fail(no_subnets_msg)
|
self.fail(no_subnets_msg)
|
||||||
|
|
||||||
self.results['actions'].append('Created default public IP {0}'.format(self.name + '01'))
|
pip = None
|
||||||
pip = self.create_default_pip(self.resource_group, self.location, self.name + '01', self.public_ip_allocation_method)
|
if self.public_ip_allocation_method != 'Disabled':
|
||||||
|
self.results['actions'].append('Created default public IP {0}'.format(self.name + '01'))
|
||||||
|
pip_info = self.create_default_pip(self.resource_group, self.location, self.name + '01', self.public_ip_allocation_method)
|
||||||
|
pip = self.network_models.PublicIPAddress(id=pip_info.id, location=pip_info.location, resource_guid=pip_info.resource_guid)
|
||||||
|
|
||||||
self.results['actions'].append('Created default security group {0}'.format(self.name + '01'))
|
self.results['actions'].append('Created default security group {0}'.format(self.name + '01'))
|
||||||
group = self.create_default_securitygroup(self.resource_group, self.location, self.name + '01', self.os_type,
|
group = self.create_default_securitygroup(self.resource_group, self.location, self.name + '01', self.os_type,
|
||||||
|
@ -1661,9 +1666,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
||||||
parameters.network_security_group = self.network_models.NetworkSecurityGroup(id=group.id,
|
parameters.network_security_group = self.network_models.NetworkSecurityGroup(id=group.id,
|
||||||
location=group.location,
|
location=group.location,
|
||||||
resource_guid=group.resource_guid)
|
resource_guid=group.resource_guid)
|
||||||
parameters.ip_configurations[0].public_ip_address = self.network_models.PublicIPAddress(id=pip.id,
|
parameters.ip_configurations[0].public_ip_address = pip
|
||||||
location=pip.location,
|
|
||||||
resource_guid=pip.resource_guid)
|
|
||||||
|
|
||||||
self.log("Creating NIC {0}".format(network_interface_name))
|
self.log("Creating NIC {0}".format(network_interface_name))
|
||||||
self.log(self.serialize_obj(parameters, 'NetworkInterface'), pretty_print=True)
|
self.log(self.serialize_obj(parameters, 'NetworkInterface'), pretty_print=True)
|
||||||
|
|
|
@ -222,6 +222,35 @@
|
||||||
- assert:
|
- assert:
|
||||||
that: azure_publicipaddresses | length == 0
|
that: azure_publicipaddresses | length == 0
|
||||||
|
|
||||||
|
- name: Create virtual machine without public ip address
|
||||||
|
register: output
|
||||||
|
azure_rm_virtualmachine:
|
||||||
|
resource_group: "{{ resource_group }}"
|
||||||
|
name: testvmnoip
|
||||||
|
vm_size: Standard_A0
|
||||||
|
admin_username: adminuser
|
||||||
|
admin_password: Password123!
|
||||||
|
short_hostname: testvm
|
||||||
|
os_type: Linux
|
||||||
|
public_ip_allocation_method: Disabled
|
||||||
|
availability_set: "avbs{{ resource_group | hash('md5') | truncate(7, True, '') }}"
|
||||||
|
image:
|
||||||
|
offer: UbuntuServer
|
||||||
|
publisher: Canonical
|
||||||
|
sku: 16.04-LTS
|
||||||
|
version: latest
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- not 'publicIPAddress' in output.ansible_facts.azure_vm.properties.networkProfile.networkInterfaces[0].properties.ipConfigurations[0].properties
|
||||||
|
|
||||||
|
- name: Delete VM with no public ip
|
||||||
|
azure_rm_virtualmachine:
|
||||||
|
resource_group: "{{ resource_group }}"
|
||||||
|
name: testvmnoip
|
||||||
|
state: absent
|
||||||
|
vm_size: Standard_A0
|
||||||
|
|
||||||
# TODO: Until we have a module to create/delete images this is the best tests
|
# TODO: Until we have a module to create/delete images this is the best tests
|
||||||
# I can do
|
# I can do
|
||||||
- name: assert error thrown with invalid image dict
|
- name: assert error thrown with invalid image dict
|
||||||
|
|
Loading…
Reference in a new issue