mirror of
https://github.com/ansible/awx.git
synced 2026-03-01 16:58:46 -03:30
Some light implimentation details for basic fact caching and collection
This commit is contained in:
27
awx/main/management/commands/run_fact_cache_receiver.py
Normal file
27
awx/main/management/commands/run_fact_cache_receiver.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# Copyright (c) 2015 Ansible, Inc.
|
||||||
|
# All Rights Reserved
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from django.core.management.base import NoArgsCommand
|
||||||
|
|
||||||
|
from awx.main.models import * # noqa
|
||||||
|
|
||||||
|
logger = logging.getLogger('awx.main.commands.run_fact_cache_receiver')
|
||||||
|
|
||||||
|
class FactCacheReceiver(object):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class Command(NoArgsCommand):
|
||||||
|
'''
|
||||||
|
blah blah
|
||||||
|
'''
|
||||||
|
help = 'Launch the Fact Cache Receiver'
|
||||||
|
|
||||||
|
def handle_noargs(self, **options):
|
||||||
|
fcr = FactCacheReceiver()
|
||||||
|
try:
|
||||||
|
fcr.run_receiver()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
|
||||||
@@ -550,6 +550,10 @@ class RunJob(BaseTask):
|
|||||||
env['JOB_ID'] = str(job.pk)
|
env['JOB_ID'] = str(job.pk)
|
||||||
env['INVENTORY_ID'] = str(job.inventory.pk)
|
env['INVENTORY_ID'] = str(job.inventory.pk)
|
||||||
env['ANSIBLE_CALLBACK_PLUGINS'] = plugin_dir
|
env['ANSIBLE_CALLBACK_PLUGINS'] = plugin_dir
|
||||||
|
# TODO: env['ANSIBLE_LIBRARY'] # plugins/library
|
||||||
|
# TODO: env['ANSIBLE_CACHE_PLUGINS'] # plugins/fact_caching
|
||||||
|
# TODD: env['ANSIBLE_CACHE_PLUGIN'] # tower
|
||||||
|
# TODO: env['ANSIBLE_CACHE_PLUGIN_CONNECTION'] # connection to tower service
|
||||||
env['REST_API_URL'] = settings.INTERNAL_API_URL
|
env['REST_API_URL'] = settings.INTERNAL_API_URL
|
||||||
env['REST_API_TOKEN'] = job.task_auth_token or ''
|
env['REST_API_TOKEN'] = job.task_auth_token or ''
|
||||||
env['CALLBACK_CONSUMER_PORT'] = str(settings.CALLBACK_CONSUMER_PORT)
|
env['CALLBACK_CONSUMER_PORT'] = str(settings.CALLBACK_CONSUMER_PORT)
|
||||||
|
|||||||
5
awx/playbooks/scan_facts.yml
Normal file
5
awx/playbooks/scan_facts.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
- hosts: all
|
||||||
|
gather_facts: no
|
||||||
|
tasks:
|
||||||
|
- scan_packages:
|
||||||
|
|
||||||
27
awx/plugins/fact_caching/tower.py
Normal file
27
awx/plugins/fact_caching/tower.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
from ansible.cache.base import BaseCacheModule
|
||||||
|
|
||||||
|
class TowerCacheModule(BaseCacheModule):
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def get(self, key):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def set(self, key, value):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def keys(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def contains(self, key):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def delete(self, key):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def flush(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def copy(self):
|
||||||
|
pass
|
||||||
37
awx/plugins/library/scan_packages.py
Executable file
37
awx/plugins/library/scan_packages.py
Executable file
@@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import os
|
||||||
|
from ansible.module_utils.basic import *
|
||||||
|
|
||||||
|
def rpm_package_list():
|
||||||
|
import rpm
|
||||||
|
trans_set = rpm.TransactionSet()
|
||||||
|
installed_packages = []
|
||||||
|
for package in trans_set.dbMatch():
|
||||||
|
installed_packages.append({'name': package['name'],
|
||||||
|
'version': "%s" % (package['version'])})
|
||||||
|
return installed_packages
|
||||||
|
|
||||||
|
def deb_package_list():
|
||||||
|
import apt
|
||||||
|
apt_cache = apt.Cache()
|
||||||
|
installed_packages = []
|
||||||
|
apt_installed_packages = [pk for pk in apt_cache.keys() if apt_cache[pk].is_installed]
|
||||||
|
for package in apt_installed_packages:
|
||||||
|
installed_packages.append({'name': package,
|
||||||
|
'version': apt_cache[package].installed.version})
|
||||||
|
return installed_packages
|
||||||
|
|
||||||
|
def main():
|
||||||
|
module = AnsibleModule(
|
||||||
|
argument_spec = dict())
|
||||||
|
|
||||||
|
packages = []
|
||||||
|
if os.path.exists("/etc/redhat-release"):
|
||||||
|
packages = rpm_package_list()
|
||||||
|
elif os.path.exists("/etc/os-release"):
|
||||||
|
packages = deb_package_list()
|
||||||
|
results = dict(ansible_facts=dict(packages=packages))
|
||||||
|
module.exit_json(**results)
|
||||||
|
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user