mirror of
https://github.com/ansible/awx.git
synced 2026-03-06 11:11:07 -03:30
Remove towervars from constructed inventory hosts (#13686)
This commit is contained in:
committed by
Rick Elrod
parent
054a70bda4
commit
ce4c1c11b3
@@ -654,13 +654,19 @@ class Command(BaseCommand):
|
|||||||
mem_host = self.all_group.all_hosts[mem_host_name]
|
mem_host = self.all_group.all_hosts[mem_host_name]
|
||||||
import_vars = mem_host.variables
|
import_vars = mem_host.variables
|
||||||
host_desc = import_vars.pop('_awx_description', 'imported')
|
host_desc = import_vars.pop('_awx_description', 'imported')
|
||||||
host_attrs = dict(variables=json.dumps(import_vars), description=host_desc)
|
host_attrs = dict(description=host_desc)
|
||||||
enabled = self._get_enabled(mem_host.variables)
|
enabled = self._get_enabled(mem_host.variables)
|
||||||
if enabled is not None:
|
if enabled is not None:
|
||||||
host_attrs['enabled'] = enabled
|
host_attrs['enabled'] = enabled
|
||||||
if self.instance_id_var:
|
if self.instance_id_var:
|
||||||
instance_id = self._get_instance_id(mem_host.variables)
|
instance_id = self._get_instance_id(mem_host.variables)
|
||||||
host_attrs['instance_id'] = instance_id
|
host_attrs['instance_id'] = instance_id
|
||||||
|
if self.inventory.kind == 'constructed':
|
||||||
|
# remote towervars so the constructed hosts do not have extra variables
|
||||||
|
for prefix in ('host', 'tower'):
|
||||||
|
for var in ('remote_{}_enabled', 'remote_{}_id'):
|
||||||
|
import_vars.pop(var.format(prefix), None)
|
||||||
|
host_attrs['variables'] = json.dumps(import_vars)
|
||||||
try:
|
try:
|
||||||
sanitize_jinja(mem_host_name)
|
sanitize_jinja(mem_host_name)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
|
|||||||
@@ -357,13 +357,12 @@ class Inventory(CommonModelNameNotUnique, ResourceMixin, RelatedJobsMixin):
|
|||||||
for host in hosts:
|
for host in hosts:
|
||||||
data['_meta']['hostvars'][host.name] = host.variables_dict
|
data['_meta']['hostvars'][host.name] = host.variables_dict
|
||||||
if towervars:
|
if towervars:
|
||||||
tower_dict = dict(
|
for prefix in ('host', 'tower'):
|
||||||
remote_tower_enabled=str(host.enabled).lower(),
|
tower_dict = {
|
||||||
remote_tower_id=host.id,
|
f'remote_{prefix}_enabled': str(host.enabled).lower(),
|
||||||
remote_host_enabled=str(host.enabled).lower(),
|
f'remote_{prefix}_id': host.id,
|
||||||
remote_host_id=host.id,
|
}
|
||||||
)
|
data['_meta']['hostvars'][host.name].update(tower_dict)
|
||||||
data['_meta']['hostvars'][host.name].update(tower_dict)
|
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user