mirror of
https://github.com/ansible/awx.git
synced 2026-04-11 21:19:22 -02:30
Use towervars to enable turning on remote tracking vars on Tower src
* This allows the local Tower to track enabled state and unique instance id for each host imported from the remote Tower
This commit is contained in:
@@ -2377,6 +2377,7 @@ class InventoryScriptView(RetrieveAPIView):
|
|||||||
obj = self.get_object()
|
obj = self.get_object()
|
||||||
hostname = request.query_params.get('host', '')
|
hostname = request.query_params.get('host', '')
|
||||||
hostvars = bool(request.query_params.get('hostvars', ''))
|
hostvars = bool(request.query_params.get('hostvars', ''))
|
||||||
|
towervars = bool(request.query_params.get('towervars', ''))
|
||||||
show_all = bool(request.query_params.get('all', ''))
|
show_all = bool(request.query_params.get('all', ''))
|
||||||
if show_all:
|
if show_all:
|
||||||
hosts_q = dict()
|
hosts_q = dict()
|
||||||
@@ -2441,6 +2442,10 @@ class InventoryScriptView(RetrieveAPIView):
|
|||||||
data['_meta'].setdefault('hostvars', dict())
|
data['_meta'].setdefault('hostvars', dict())
|
||||||
for host in obj.hosts.filter(**hosts_q):
|
for host in obj.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=host.enabled,
|
||||||
|
remote_tower_id=host.id)
|
||||||
|
data['_meta']['hostvars'][host.name].update(tower_dict)
|
||||||
|
|
||||||
return Response(data)
|
return Response(data)
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ def parse_configuration():
|
|||||||
def read_tower_inventory(tower_host, tower_user, tower_pass, inventory, ignore_ssl=False):
|
def read_tower_inventory(tower_host, tower_user, tower_pass, inventory, ignore_ssl=False):
|
||||||
if not re.match('(?:http|https)://', tower_host):
|
if not re.match('(?:http|https)://', tower_host):
|
||||||
tower_host = "https://{}".format(tower_host)
|
tower_host = "https://{}".format(tower_host)
|
||||||
inventory_url = urljoin(tower_host, "/api/v2/inventories/{}/script/?hostvars=1".format(inventory))
|
inventory_url = urljoin(tower_host, "/api/v2/inventories/{}/script/?hostvars=1&towervars=1".format(inventory))
|
||||||
try:
|
try:
|
||||||
response = requests.get(inventory_url,
|
response = requests.get(inventory_url,
|
||||||
auth=HTTPBasicAuth(tower_user, tower_pass),
|
auth=HTTPBasicAuth(tower_user, tower_pass),
|
||||||
|
|||||||
@@ -835,12 +835,12 @@ OVIRT4_INSTANCE_ID_VAR = 'id'
|
|||||||
# ---------------------
|
# ---------------------
|
||||||
# ----- Tower -----
|
# ----- Tower -----
|
||||||
# ---------------------
|
# ---------------------
|
||||||
TOWER_ENABLED_VAR = 'status'
|
TOWER_ENABLED_VAR = 'remote_tower_enabled'
|
||||||
TOWER_ENABLED_VALUE = 'enabled'
|
TOWER_ENABLED_VALUE = 'true'
|
||||||
TOWER_GROUP_FILTER = r'^.+$'
|
TOWER_GROUP_FILTER = r'^.+$'
|
||||||
TOWER_HOST_FILTER = r'^.+$'
|
TOWER_HOST_FILTER = r'^.+$'
|
||||||
TOWER_EXCLUDE_EMPTY_GROUPS = True
|
TOWER_EXCLUDE_EMPTY_GROUPS = True
|
||||||
TOWER_INSTANCE_ID_VAR = 'id'
|
TOWER_INSTANCE_ID_VAR = 'remote_tower_id'
|
||||||
|
|
||||||
# ---------------------
|
# ---------------------
|
||||||
# ----- Foreman -----
|
# ----- Foreman -----
|
||||||
|
|||||||
Reference in New Issue
Block a user