Some light implimentation details for basic fact caching and collection

This commit is contained in:
Matthew Jones
2015-02-19 11:27:40 -05:00
parent 6e18c6d3c0
commit fed4262ee2
6 changed files with 102 additions and 2 deletions

View 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

View File

@@ -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)

View File

@@ -0,0 +1,5 @@
- hosts: all
gather_facts: no
tasks:
- scan_packages:

View 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

View 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()