Exemple #1
0
 def v2_playbook_on_task_start(self, task, is_conditional):
     wsmsg = dict(
         rc=self.RC_SUCC,
         task_name=self.current_taskname,
         msg=dict(kind='task_start', value=task.get_name())
     )
     message.sendmsg(wsmsg, message.MSGTYPE_NOTICE)
Exemple #2
0
    def v2_playbook_on_stats(self, stats):
        #self.display('PLAY SUMMARIZE')

        hosts = sorted(stats.processed.keys())
        details = {}
        return_code = 0
        for h in hosts:
            t = stats.summarize(h)
            rc = 1 if t['unreachable'] or t['failures'] else 0
            details[h] = {
                'host': h,
                'rc': rc,
                'unreachable': t['unreachable'],
                'skipped': t['skipped'],
                'ok': t['ok'],
                'changed': t['changed'],
                'failures': t['failures']
            }
            #self.display('Host:%s, Stat:%s'% (h,str(t)),rc)
            return_code += rc
        message.sendmsg(
            {
                'rc': return_code,
                'task_name': self.current_taskname,
                'msg': {
                    'kind': 'play_summarize',
                    'list': details
                }
            }, message.MSGTYPE_NOTICE)
Exemple #3
0
 def v2_runner_retry(self, result):
     msg = "FAILED - RETRYING: %s (%d retries left)." % (
         result._task,
         result._result['retries'] - result._result['attempts'])
     message.sendmsg(
         {
             'rc': self.RC_FAIL,
             'task_name': self.current_taskname,
             'msg': {
                 'kind': 'needs_retry',
                 'value': result._task
             }
         }, message.MSGTYPE_NOTICE)
Exemple #4
0
 def v2_playbook_on_play_start(self, play):
     palyname = play.get_name().strip()
     self.current_taskname = palyname
     hosts = play._attributes.get('hosts')[0].split(',')  # why is list[0]
     message.sendmsg(
         {
             'rc': self.RC_SUCC,
             'task_name': self.current_taskname,
             'task_count': len(hosts),
             'msg': {
                 'kind': 'play_start',
                 'value': palyname
             }
         }, message.MSGTYPE_NOTICE)
Exemple #5
0
    def v2_playbook_on_play_start(self, play):
        palyname = play.get_name().strip()
        task = list()
        host = list()
        for t in play.get_tasks():
            tmp = [i.get_name() for i in t]
            task = list(set(task + tmp))
        for h_str in play._attributes.get('hosts'):
            h = h_str.split(',')
            host = list(set(host + h))

        self.current_taskname = palyname
        wsmsg = dict(rc=self.RC_SUCC,
                     task_name=palyname,
                     task_list=task,
                     host_list=host,
                     msg=dict(kind='play_start', value=palyname))
        message.sendmsg(wsmsg, message.MSGTYPE_NOTICE)
        self.reset_output()
Exemple #6
0
    def v2_on_any(self, *args, **kwargs):

        wsmsg = dict(
            msg=dict(), rc=self.RC_SUCC,
            task_name=self.current_taskname,
        )

        for crucial in args:
            if isinstance(crucial, TypeTaskResult):
                item = self._fill_item_from_taskresult(
                    init_data=dict(
                        host=crucial._host.get_name(),
                        task_name=crucial._task.get_name(),
                        rc=self.RC_SUCC
                    ), detail=crucial._result)

                if self.std_lines.get(item['host']) == None:
                    self.std_lines[item['host']] = []

                self.std_lines[item['host']].append(item)
                wsmsg['rc'] = item['rc']
                wsmsg['msg'] = item
                message.sendmsg(wsmsg, message.MSGTYPE_INFO)
            elif isinstance(crucial, TypeTask):
                pass
            elif isinstance(crucial, TypePlay):
                pass
                # print(crucial)
            elif isinstance(crucial, TypeAggregateStats):
                hosts = sorted(crucial.processed.keys())
                wsmsg = dict(
                    rc=self.RC_SUCC,
                    task_name=self.current_taskname,
                    msg=dict(kind='play_summarize', list=dict())
                )
                for h in hosts:
                    t = crucial.summarize(h)
                    c = 1 if t['unreachable'] or t['failures'] else 0
                    wsmsg['msg']['list'][h] = dict(
                        host=h, rc=c, unreachable=t[
                            'unreachable'], skipped=t['skipped'],
                        ok=t['ok'], changed=t[
                            'changed'], failures=t['failures']
                    )
                    wsmsg['rc'] += c
                message.sendmsg(wsmsg, message.MSGTYPE_NOTICE)
            elif isinstance(crucial, unicode) or isinstance(crucial, str):
                wsmsg = dict(
                    rc=self.RC_SUCC,
                    task_name=self.current_taskname,
                    msg=dict(kind='desc', unique=crucial)
                )
                message.sendmsg(wsmsg, message.MSGTYPE_NOTICE)
            else:
                Tool.LOGGER.warning(
                    'Found a new type in result [%s]' % (type(crucial)))
Exemple #7
0
    def display(self, result, rc):
        params = {
            'msg': {},
            'task_name': self.current_taskname,
            'rc': rc,
            'ctime': ''
        }
        if isinstance(result, TaskResult):
            params['msg']['host'] = result._host.get_name()
            params['msg']['module'] = result._task.get_name()
            detail = result._result
            # print(detail)
            if result.is_changed():
                params['rc'] = self.RC_SUCC
                if detail['invocation'].get('module_name') == 'command':
                    params['msg']['unique'] = {'cost_time': detail['delta']}
                elif detail['invocation'].get('module_name') == 'script':
                    params['msg']['unique'] = {
                        'script_file':
                        detail['invocation']['module_args']['_raw_params']
                    }
                elif detail.get('state'):
                    params['msg']['unique'] = {'state': detail['state']}
                elif detail.get('cmd'):
                    params['msg']['unique'] = {'cmd': detail['cmd']}
                else:
                    print('Found a new type in TaskResult')
            elif detail.get('msg', '') != '':  # 有msg信息 认为出现了错误
                params['rc'] = self.RC_FAIL
                params['msg']['error'] = detail['msg']
            else:
                params['rc'] = self.RC_SUCC
                print("is_changed=false")
                print(detail)
                #params['msg']['unique'] = {'unknown':detail['msg']}

            message.sendmsg(params, message.MSGTYPE_INFO)

        elif isinstance(result, unicode) or isinstance(result, str):
            params['rc'] = rc
            params['msg']['kind'] = 'desc'
            params['msg']['unique'] = result
            message.sendmsg(params, message.MSGTYPE_NOTICE)
        elif isinstance(result, Task):
            params['rc'] = rc
            params['msg']['kind'] = 'task'
            params['msg']['value'] = result.get_name()
            message.sendmsg(params, message.MSGTYPE_NOTICE)
        else:
            print('Found a new type in result [%s]' % (type(result)))