From f97abc095b244038b4e4d59fb7919ba15643c230 Mon Sep 17 00:00:00 2001 From: Ids van der Molen Date: Tue, 15 Jan 2019 19:24:52 +0100 Subject: [PATCH] gcp_compute: Add vars_prefix to prefix host_vars (#49601) * Add vars_prefix to prefix host_vars * Set vars_prefix default to empty string --- lib/ansible/plugins/inventory/gcp_compute.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/ansible/plugins/inventory/gcp_compute.py b/lib/ansible/plugins/inventory/gcp_compute.py index a1180a039c9..3be4ca5b07a 100644 --- a/lib/ansible/plugins/inventory/gcp_compute.py +++ b/lib/ansible/plugins/inventory/gcp_compute.py @@ -48,6 +48,9 @@ DOCUMENTATION = ''' description: - An optional service account email address if machineaccount is selected 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 = ''' @@ -111,7 +114,10 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): hostname = self._get_hostname(item) self.inventory.add_host(hostname) 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) def verify_file(self, path):