1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

support for custom data in vmss (#51380)

This commit is contained in:
Zim Kalinowski 2019-01-30 12:09:29 +08:00 committed by GitHub
parent 670a45c3ac
commit f0f23378db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 6 deletions

View file

@ -206,6 +206,14 @@ options:
- A list of Availability Zones for your virtual machine scale set
type: list
version_added: "2.8"
custom_data:
description:
- Data which is made available to the virtual machine and used by e.g., cloud-init.
- Many images in the marketplace are not cloud-init ready. Thus, data
sent to I(custom_data) would be ignored. If the image you are attempting to use is not listed in
U(https://docs.microsoft.com/en-us/azure/virtual-machines/linux/using-cloud-init#cloud-init-overview),
follow these steps U(https://docs.microsoft.com/en-us/azure/virtual-machines/linux/cloudinit-prepare-custom-image).
version_added: "2.8"
extends_documentation_fragment:
- azure
@ -365,6 +373,7 @@ azure_vmss:
import random
import re
import base64
try:
from msrestazure.azure_exceptions import CloudError
@ -375,6 +384,7 @@ except ImportError:
pass
from ansible.module_utils.azure_rm_common import AzureRMModuleBase, azure_id_to_dict, format_resource_id
from ansible.module_utils.basic import to_native, to_bytes
AZURE_OBJECT_CLASS = 'VirtualMachineScaleSet'
@ -414,7 +424,8 @@ class AzureRMVirtualMachineScaleSet(AzureRMModuleBase):
enable_accelerated_networking=dict(type='bool'),
security_group=dict(type='raw', aliases=['security_group_name']),
overprovision=dict(type='bool', default=True),
zones=dict(type='list')
zones=dict(type='list'),
custom_data=dict(type='str')
)
self.resource_group = None
@ -445,6 +456,7 @@ class AzureRMVirtualMachineScaleSet(AzureRMModuleBase):
self.security_group = None
self.overprovision = None
self.zones = None
self.custom_data = None
required_if = [
('state', 'present', [
@ -498,6 +510,9 @@ class AzureRMVirtualMachineScaleSet(AzureRMModuleBase):
# Set default location
self.location = resource_group.location
if self.custom_data:
self.custom_data = to_native(base64.b64encode(to_bytes(self.custom_data)))
if self.state == 'present':
# Verify parameters and resolve any defaults
@ -627,6 +642,12 @@ class AzureRMVirtualMachineScaleSet(AzureRMModuleBase):
differences.append('load_balancer')
changed = True
if self.custom_data:
if self.custom_data != vmss_dict['properties']['virtualMachineProfile']['osProfile'].get('customData'):
differences.append('custom_data')
changed = True
vmss_dict['properties']['virtualMachineProfile']['osProfile']['customData'] = self.custom_data
self.differences = differences
elif self.state == 'absent':
@ -698,6 +719,7 @@ class AzureRMVirtualMachineScaleSet(AzureRMModuleBase):
os_profile=self.compute_models.VirtualMachineScaleSetOSProfile(
admin_username=self.admin_username,
computer_name_prefix=self.short_hostname,
custom_data=self.custom_data
),
storage_profile=self.compute_models.VirtualMachineScaleSetStorageProfile(
os_disk=self.compute_models.VirtualMachineScaleSetOSDisk(

View file

@ -152,6 +152,7 @@
tier: Standard
managed_disk_type: Standard_LRS
os_disk_caching: ReadWrite
custom_data: "#cloud-config"
image:
offer: CoreOS
publisher: CoreOS
@ -184,6 +185,7 @@
tier: Standard
managed_disk_type: Standard_LRS
os_disk_caching: ReadWrite
custom_data: "#cloud-config"
image:
offer: CoreOS
publisher: CoreOS
@ -353,7 +355,7 @@
resource_group: "{{ resource_group }}"
name: testVMSS{{ rpfx }}2
vm_size: Standard_D3_v2
capacity: 1
capacity: 0
virtual_network_name: testVnet
subnet_name: testSubnet
admin_username: testuser
@ -377,7 +379,7 @@
resource_group: "{{ resource_group }}"
name: testVMSS{{ rpfx }}2
vm_size: Standard_D3_v2
capacity: 1
capacity: 0
virtual_network_name: testVnet
subnet_name: testSubnet
admin_username: testuser
@ -403,7 +405,7 @@
resource_group: "{{ resource_group }}"
name: testVMSS{{ rpfx }}2
vm_size: Standard_D3_v2
capacity: 1
capacity: 0
virtual_network_name: testVnet
subnet_name: testSubnet
admin_username: testuser
@ -427,7 +429,7 @@
resource_group: "{{ resource_group }}"
name: testVMSS{{ rpfx }}2
vm_size: Standard_D3_v2
capacity: 1
capacity: 0
virtual_network_name: testVnet
subnet_name: testSubnet
admin_username: testuser
@ -451,7 +453,7 @@
resource_group: "{{ resource_group }}"
name: testVMSS{{ rpfx }}2
vm_size: Standard_B1s
capacity: 1
capacity: 0
virtual_network_name: testVnet
subnet_name: testSubnet
admin_username: testuser