Ejemplo n.º 1
0
 def setUp(self):
     self.testdir = 'testdata/sosreport_dir'
     self.cleaner = SOSCleaner(quiet=True)
     self.cleaner.origin_path, self.cleaner.dir_path, self.cleaner.session, self.cleaner.logfile, self.cleaner.uuid = self.cleaner._prep_environment(
     )
     self.cleaner._start_logging(self.cleaner.logfile)
     self._setUpHostname()
 def done(self, config, rm_conf):
     """
     Do finalization stuff
     """
     if config.getboolean(APP_NAME, "obfuscate"):
         cleaner = SOSCleaner(quiet=True)
         clean_opts = CleanOptions(self.archive.tmp_dir, config, rm_conf)
         fresh = cleaner.clean_report(clean_opts, self.archive.archive_dir)
         if clean_opts.keyword_file is not None:
             os.remove(clean_opts.keyword_file.name)
         return fresh[0]
     return self.archive.create_tar_file()
Ejemplo n.º 3
0
def run_module():
    # define available arguments/parameters a user can pass to the module
    module_args = dict(
        sosreport=dict(type='path', required=True),
        domains=dict(type='list', required=False),
        networks=dict(type='list', required=False),
        users=dict(type='list', required=False),
        keywords=dict(type='list', required=False),
        loglevel=dict(
            choices=['INFO', 'WARNING', 'ERROR', 'CRITICAL', 'DEBUG'],
            default='INFO'),
        report_dir=dict(type='path', required=False, default='/tmp'),
    )

    # seed the result dict in the object
    # we primarily care about changed and state
    # change is if this module effectively modified the target
    # state will include any data that you want your module to pass back
    # for consumption, for example, in a subsequent task
    result = dict(
        changed=False,
        sosreport_path='',
        obfuscated_report_path='',
        hostname_report='',
        domainname_report='',
        ip_report='',
        user_report='',
        mac_report='',
        keyword_report='',
    )

    # the AnsibleModule object will be our abstraction working with Ansible
    # this includes instantiation, a couple of common attr would be the
    # args/params passed to the execution, as well as if the module
    # supports check mode
    module = AnsibleModule(argument_spec=module_args, supports_check_mode=True)

    # if the user is working with this module in only check mode we do not
    # want to make any changes to the environment, just return the current
    # state with no modifications
    if module.check_mode:
        return result

    class param_options:
        pass

    param_options.domains = module.params['domains']
    param_options.networks = module.params['networks']
    param_options.users = module.params['users']
    param_options.keywords = module.params['keywords']
    param_options.loglevel = module.params['loglevel']
    param_options.report_dir = module.params['report_dir']
    param_options.keywords_file = None
    param_options.users_file = None
    param_options.hostname_path = None
    param_options.files = None

    cleaner = SOSCleaner()
    cleaner.loglevel = module.params['loglevel']
    cleaner.quiet = True
    cleaner.origin_path, cleaner.dir_path, cleaner.session, cleaner.logfile, cleaner.uuid = cleaner._prep_environment(
    )
    cleaner._start_logging(cleaner.logfile)

    cleaner.clean_report(param_options, module.params['sosreport'])

    # manipulate or modify the state as needed (this is going to be the
    # part where your module will do what it needs to do)
    result['sosreport_path'] = module.params['sosreport'],
    result['obfuscated_report_path'] = cleaner.archive_path,
    result['hostname_report'] = cleaner.hn_report,
    result['domainname_report'] = cleaner.dn_report,
    result['ip_report'] = cleaner.ip_report,
    result['user_report'] = cleaner.un_report,
    result['mac_report'] = cleaner.mac_report,
    result['keyword_report'] = cleaner.kw_report,
    result['changed'] = True

    # during the execution of the module, if there is an exception or a
    # conditional state that effectively causes a failure, run
    # AnsibleModule.fail_json() to pass in the message and the result
    # in the event of a successful module execution, you will want to
    # simple AnsibleModule.exit_json(), passing the key/value results
    module.exit_json(**result)