mirror of
https://github.com/ansible/awx.git
synced 2026-04-14 06:29:25 -02:30
add back in support of towervars lost in merge
This commit is contained in:
@@ -2443,7 +2443,8 @@ class InventoryScriptView(RetrieveAPIView):
|
|||||||
host = get_object_or_404(obj.hosts, **hosts_q)
|
host = get_object_or_404(obj.hosts, **hosts_q)
|
||||||
return Response(host.variables_dict)
|
return Response(host.variables_dict)
|
||||||
return Response(obj.get_script_data(
|
return Response(obj.get_script_data(
|
||||||
hostvars=bool(request.query_params.get('hostvars', '')),
|
hostvars=hostvars,
|
||||||
|
towervars=towervars,
|
||||||
show_all=show_all
|
show_all=show_all
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ class Inventory(CommonModelNameNotUnique, ResourceMixin):
|
|||||||
group_children.add(from_group_id)
|
group_children.add(from_group_id)
|
||||||
return group_children_map
|
return group_children_map
|
||||||
|
|
||||||
def get_script_data(self, hostvars=False, show_all=False):
|
def get_script_data(self, hostvars=False, towervars=False, show_all=False):
|
||||||
if show_all:
|
if show_all:
|
||||||
hosts_q = dict()
|
hosts_q = dict()
|
||||||
else:
|
else:
|
||||||
@@ -271,6 +271,10 @@ class Inventory(CommonModelNameNotUnique, ResourceMixin):
|
|||||||
data['_meta'].setdefault('hostvars', dict())
|
data['_meta'].setdefault('hostvars', dict())
|
||||||
for host in self.hosts.filter(**hosts_q):
|
for host in self.hosts.filter(**hosts_q):
|
||||||
data['_meta']['hostvars'][host.name] = host.variables_dict
|
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)
|
||||||
|
data['_meta']['hostvars'][host.name].update(tower_dict)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,28 @@ from awx.main.models import (
|
|||||||
from awx.main.utils.filters import SmartFilter
|
from awx.main.utils.filters import SmartFilter
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
class TestInventoryScript:
|
||||||
|
|
||||||
|
def test_hostvars(self, inventory):
|
||||||
|
inventory.hosts.create(name='ahost', variables={"foo": "bar"})
|
||||||
|
assert inventory.get_script_data(
|
||||||
|
hostvars=True
|
||||||
|
)['_meta']['hostvars']['ahost'] == {
|
||||||
|
'foo': 'bar'
|
||||||
|
}
|
||||||
|
|
||||||
|
def test_towervars(self, inventory):
|
||||||
|
host = inventory.hosts.create(name='ahost')
|
||||||
|
assert inventory.get_script_data(
|
||||||
|
hostvars=True,
|
||||||
|
towervars=True
|
||||||
|
)['_meta']['hostvars']['ahost'] == {
|
||||||
|
'remote_tower_enabled': 'true',
|
||||||
|
'remote_tower_id': host.id
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
class TestSCMUpdateFeatures:
|
class TestSCMUpdateFeatures:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user