Make safe variable duplications for rename (#5093)

* Make safe variable duplications to controller

* Back out some changes to be smarter

* Update test to new vars
This commit is contained in:
Alan Rominger 2021-06-18 14:14:07 -04:00 committed by Shane McDonald
parent 95e796a88a
commit a8083296e6
No known key found for this signature in database
GPG Key ID: 6F374AF6E9EB9374
3 changed files with 9 additions and 1 deletions

View File

@ -306,7 +306,12 @@ class Inventory(CommonModelNameNotUnique, ResourceMixin, RelatedJobsMixin):
for host in hosts:
data['_meta']['hostvars'][host.name] = host.variables_dict
if towervars:
tower_dict = dict(remote_tower_enabled=str(host.enabled).lower(), remote_tower_id=host.id)
tower_dict = dict(
remote_tower_enabled=str(host.enabled).lower(),
remote_tower_id=host.id,
remote_host_enabled=str(host.enabled).lower(),
remote_host_id=host.id,
)
data['_meta']['hostvars'][host.name].update(tower_dict)
return data

View File

@ -22,6 +22,8 @@ class TestInventoryScript:
assert inventory.get_script_data(hostvars=True, towervars=True)['_meta']['hostvars']['ahost'] == {
'remote_tower_enabled': 'true',
'remote_tower_id': host.id,
'remote_host_enabled': 'true',
'remote_host_id': host.id,
}
def test_all_group(self, inventory):

View File

@ -176,6 +176,7 @@ class InventoryModule(BaseInventoryPlugin):
for key in ('version', 'ansible_version'):
server_data[key] = config_data.get(key, 'unknown')
self.inventory.set_variable('all', 'tower_metadata', server_data)
self.inventory.set_variable('all', 'controller_metadata', server_data)
# Clean up the inventory.
self.inventory.reconcile_inventory()