def main()

in plugins/modules/ali_oos_execution.py [0:0]


def main():
    argument_spec = ecs_argument_spec()
    argument_spec.update(dict(
        state=dict(default='present', choices=['present', 'absent', 'cancel', 'notify']),
        execution_ids=dict(type='list', elements='str'),
        description=dict(type='str'),
        template_name=dict(type='str', aliases=['name']),
        loop_mode=dict(type='str'),
        mode=dict(type='str', choices=['Debug', 'Automatic']),
        parameters=dict(type='dict'),
        parent_execution_id=dict(type='str'),
        safety_check=dict(type='str', default='ConfirmEveryHighRiskAction', choices=['Skip', 'ConfirmEveryHighRiskAction']),
        tags=dict(type='dict'),

        status=dict(type='str'),
        executed_by=dict(type='str'),

        notify_type=dict(type='str', choices=['Approve', 'Reject', 'ExecuteTask', 'CancelTask', 'CompleteExecution']),
        execution_status=dict(type='str'),
        loop_item=dict(type='str'),
        notify_note=dict(type='str'),
        task_execution_id=dict(type='str'),
        task_name=dict(type='str')
    ))

    module = AnsibleModule(argument_spec=argument_spec)

    if HAS_FOOTMARK is False:
        module.fail_json(msg='footmark required for this module.')

    oos_conn = oos_connect(module)

    # Get values of variable
    state = module.params['state']

    template_name = module.params['template_name']
    status = module.params['status']
    executed_by = module.params['executed_by']
    params = {}

    if template_name:
        params['template_name'] = template_name
    if status:
        params['status'] = status
    if executed_by:
        params['executed_by'] = executed_by
    changed = False
    if params:
        module.params['params'] = params

    if state == 'absent':
        ids = executions_exists(module, oos_conn)
        try:
            if oos_conn.delete_executions(execution_ids=ids):
                changed = True
            module.exit_json(changed=changed, executions={})
        except OOSResponseError as e:
            module.fail_json(msg='Unable to delete executions {0}, error: {1}'.format(str(ids), e))

    elif state == 'cancel':
        ids = executions_exists(module, oos_conn)
        try:
            if ids:
                for i in ids:
                    if oos_conn.cancel_execution(execution_id=i):
                        changed = True
            module.exit_json(changed=changed, executions={})
        except OOSResponseError as e:
            module.fail_json(msg='Unable to cancel executions {0}, error: {1}'.format(str(ids), e))

    elif state == 'present':
        client_token = "Ansible-Alicloud-{0}-{1}".format(hash(str(module.params)), str(time.time()))
        module.params['client_token'] = client_token
        execution = oos_conn.start_execution(**module.params)
        if execution:
            changed = True
        module.exit_json(changed=changed, executions=execution.read())

    else:
        excutions = []
        ids = executions_exists(module, oos_conn)
        if ids:
            for i in ids:
                module.params['execution_id'] = i
                if oos_conn.notify_execution(**module.params):
                    changed = True
                excutions.append(oos_conn.list_executions(execution_id=i)[0].read())

        module.exit_json(changed=changed, excutions=excutions)