Allow using Azure rm legacy hostnames (#54060)
This commit is contained in:
parent
fe0765eb2b
commit
461737e2da
2 changed files with 21 additions and 4 deletions
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
minor_changes:
|
||||||
|
- add option to azure_rm inventory plugin which will allow the legacy script host names to be used
|
|
@ -74,6 +74,15 @@ DOCUMENTATION = r'''
|
||||||
type: bool
|
type: bool
|
||||||
default: False
|
default: False
|
||||||
version_added: '2.8'
|
version_added: '2.8'
|
||||||
|
plain_host_names:
|
||||||
|
description:
|
||||||
|
- By default this plugin will use globally unique host names.
|
||||||
|
This option allows you to override that, and use the name that matches the old inventory script naming.
|
||||||
|
- This is not the default, as these names are not truly unique, and can conflict with other hosts.
|
||||||
|
The default behavior will add extra hashing to the end of the hostname to prevent such conflicts.
|
||||||
|
type: bool
|
||||||
|
default: False
|
||||||
|
version_added: '2.8'
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
|
@ -247,6 +256,8 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
|
||||||
|
|
||||||
self._batch_fetch = self.get_option('batch_fetch')
|
self._batch_fetch = self.get_option('batch_fetch')
|
||||||
|
|
||||||
|
self._legacy_hostnames = self.get_option('plain_host_names')
|
||||||
|
|
||||||
self._filters = self.get_option('exclude_host_filters') + self.get_option('default_host_filters')
|
self._filters = self.get_option('exclude_host_filters') + self.get_option('default_host_filters')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -373,7 +384,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
|
||||||
if 'value' in response:
|
if 'value' in response:
|
||||||
for h in response['value']:
|
for h in response['value']:
|
||||||
# FUTURE: add direct VM filtering by tag here (performance optimization)?
|
# FUTURE: add direct VM filtering by tag here (performance optimization)?
|
||||||
self._hosts.append(AzureHost(h, self, vmss=vmss))
|
self._hosts.append(AzureHost(h, self, vmss=vmss, legacy_name=self._legacy_hostnames))
|
||||||
|
|
||||||
def _on_vmss_page_response(self, response):
|
def _on_vmss_page_response(self, response):
|
||||||
next_link = response.get('nextLink')
|
next_link = response.get('nextLink')
|
||||||
|
@ -479,7 +490,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
|
||||||
class AzureHost(object):
|
class AzureHost(object):
|
||||||
_powerstate_regex = re.compile('^PowerState/(?P<powerstate>.+)$')
|
_powerstate_regex = re.compile('^PowerState/(?P<powerstate>.+)$')
|
||||||
|
|
||||||
def __init__(self, vm_model, inventory_client, vmss=None):
|
def __init__(self, vm_model, inventory_client, vmss=None, legacy_name=False):
|
||||||
self._inventory_client = inventory_client
|
self._inventory_client = inventory_client
|
||||||
self._vm_model = vm_model
|
self._vm_model = vm_model
|
||||||
self._vmss = vmss
|
self._vmss = vmss
|
||||||
|
@ -489,8 +500,11 @@ class AzureHost(object):
|
||||||
self._powerstate = "unknown"
|
self._powerstate = "unknown"
|
||||||
self.nics = []
|
self.nics = []
|
||||||
|
|
||||||
# Azure often doesn't provide a globally-unique filename, so use resource name + a chunk of ID hash
|
if legacy_name:
|
||||||
self.default_inventory_hostname = '{0}_{1}'.format(vm_model['name'], hashlib.sha1(to_bytes(vm_model['id'])).hexdigest()[0:4])
|
self.default_inventory_hostname = vm_model['name']
|
||||||
|
else:
|
||||||
|
# Azure often doesn't provide a globally-unique filename, so use resource name + a chunk of ID hash
|
||||||
|
self.default_inventory_hostname = '{0}_{1}'.format(vm_model['name'], hashlib.sha1(to_bytes(vm_model['id'])).hexdigest()[0:4])
|
||||||
|
|
||||||
self._hostvars = {}
|
self._hostvars = {}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue