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

gcp_compute: Add vars_prefix to prefix host_vars (#49601)

* Add vars_prefix to prefix host_vars

* Set vars_prefix default to empty string
This commit is contained in:
Ids van der Molen 2019-01-15 19:24:52 +01:00 committed by ansibot
parent 332dc6a93a
commit f97abc095b

View file

@ -48,6 +48,9 @@ DOCUMENTATION = '''
description: description:
- An optional service account email address if machineaccount is selected - An optional service account email address if machineaccount is selected
and the user does not wish to use the default email. and the user does not wish to use the default email.
vars_prefix:
description: prefix to apply to host variables, does not include facts nor params
default: ''
''' '''
EXAMPLES = ''' EXAMPLES = '''
@ -111,7 +114,10 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
hostname = self._get_hostname(item) hostname = self._get_hostname(item)
self.inventory.add_host(hostname) self.inventory.add_host(hostname)
for key in item: for key in item:
self.inventory.set_variable(hostname, key, item[key]) try:
self.inventory.set_variable(hostname, self.get_option('vars_prefix') + key, item[key])
except (ValueError, TypeError) as e:
self.display.warning("Could not set host info hostvar for %s, skipping %s: %s" % (hostname, key, to_native(e)))
self.inventory.add_child('all', hostname) self.inventory.add_child('all', hostname)
def verify_file(self, path): def verify_file(self, path):