mirror of https://github.com/jumpserver/jumpserver
pref: 完成收集资产信息任务
parent
4e8e4e4bb7
commit
6a33129349
|
@ -133,7 +133,7 @@ class BasePlaybookManager:
|
|||
summary = cb.summary
|
||||
for state, hosts in summary.items():
|
||||
for host in hosts:
|
||||
result = cb.result.get(host)
|
||||
result = cb.host_results.get(host)
|
||||
if state == 'ok':
|
||||
self.on_host_success(host, result)
|
||||
else:
|
||||
|
|
|
@ -2,11 +2,13 @@
|
|||
#
|
||||
#
|
||||
from .change_secret.manager import ChangeSecretManager
|
||||
from .gather_facts.manager import GatherFactsManager
|
||||
|
||||
|
||||
class ExecutionManager:
|
||||
manager_type_mapper = {
|
||||
'change_secret': ChangeSecretManager,
|
||||
'gather_facts': GatherFactsManager,
|
||||
}
|
||||
|
||||
def __init__(self, execution):
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
# all base inventory in base/base_inventory.txt
|
||||
asset_name(ip) ...base_inventory_vars
|
||||
asset_name ...base_inventory_vars
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
- hosts: windows
|
||||
gather_facts: yes
|
||||
tasks:
|
||||
# - name: Gather facts windows
|
||||
# setup:
|
||||
# register: facts
|
||||
#
|
||||
# - debug:
|
||||
# var: facts
|
||||
- name: Get info
|
||||
set_fact:
|
||||
info:
|
||||
|
@ -19,6 +13,6 @@
|
|||
sn: "{{ ansible_product_serial }}"
|
||||
cpu_vcpus: "{{ ansible_processor_vcpus }}"
|
||||
memory: "{{ ansible_memtotal_mb }}"
|
||||
t
|
||||
|
||||
- debug:
|
||||
var: info
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
from common.utils import get_logger
|
||||
from ..base.manager import BasePlaybookManager
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
class GatherFactsManager(BasePlaybookManager):
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
@ -13,10 +16,16 @@ class GatherFactsManager(BasePlaybookManager):
|
|||
def host_callback(self, host, asset=None, **kwargs):
|
||||
super().host_callback(host, asset=asset, **kwargs)
|
||||
self.host_asset_mapper[host['name']] = asset
|
||||
return host
|
||||
|
||||
def on_host_success(self, host, result):
|
||||
print("Host: {}".format(host))
|
||||
print("Result: {}".format(result))
|
||||
info = result.get('Get info', {}).get('res', {}).get('ansible_facts', {}).get('info', {})
|
||||
asset = self.host_asset_mapper.get(host)
|
||||
if asset and info:
|
||||
asset.info = info
|
||||
asset.save()
|
||||
else:
|
||||
logger.error("Not found info, task name must be 'Get info': {}".format(host))
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -19,12 +19,14 @@ logger = get_logger(__file__)
|
|||
|
||||
def update_asset_hardware_info_on_created(asset):
|
||||
logger.debug("Update asset `{}` hardware info".format(asset))
|
||||
update_assets_hardware_info_util.delay([asset])
|
||||
# Todo:
|
||||
# update_assets_hardware_info_util.delay([asset])
|
||||
|
||||
|
||||
def test_asset_conn_on_created(asset):
|
||||
logger.debug("Test asset `{}` connectivity".format(asset))
|
||||
test_asset_connectivity_util.delay([asset])
|
||||
# Todo:
|
||||
# test_asset_connectivity_util.delay([asset])
|
||||
|
||||
|
||||
@receiver(pre_save, sender=Node)
|
||||
|
|
|
@ -18,6 +18,14 @@ class DefaultCallback:
|
|||
self.status = 'running'
|
||||
self.finished = False
|
||||
|
||||
@property
|
||||
def host_results(self):
|
||||
results = {}
|
||||
for state, hosts in self.result.items():
|
||||
for host, items in hosts.items():
|
||||
results[host] = items
|
||||
return results
|
||||
|
||||
def is_success(self):
|
||||
return self.status != 'successful'
|
||||
|
||||
|
|
|
@ -181,13 +181,13 @@ class JMSInventory:
|
|||
else:
|
||||
hosts.append(host)
|
||||
|
||||
exclude_hosts = list(filter(lambda x: x.get('exclude'), hosts))
|
||||
exclude_hosts = list(filter(lambda x: x.get('error'), hosts))
|
||||
if exclude_hosts:
|
||||
print(_("Skip hosts below:"))
|
||||
for i, host in enumerate(exclude_hosts, start=1):
|
||||
print("{}: [{}] \t{}".format(i, host['name'], host['error']))
|
||||
|
||||
hosts = list(filter(lambda x: not x.get('exclude'), hosts))
|
||||
hosts = list(filter(lambda x: not x.get('error'), hosts))
|
||||
data = {'all': {'hosts': {}}}
|
||||
for host in hosts:
|
||||
name = host.pop('name')
|
||||
|
|
Loading…
Reference in New Issue