def run_normal(params, result):
    """
    Normal mode logic.

    params contains input parameters.

    result contains run results skeleton, will modify/add to and then return
    this value along with an err value that contains None if no error or a string
    describing the error.
    """

    # Return data
    err = None
    version = ''
    steps = []

    # Parameters
    domain = params['domain']
    username = params['username']
    password = params['password']
    servers = params['servers']
    timeout = params['timeout']
    timesync = params['timesync']
    extra_args = params['extra_args']
    facts = params['facts']
    facts_verbose = params['facts_verbose']
    facts_key = params['facts_key'] if params[
        'facts_key'] else FACTS_KEY_DEFAULT
    path = params['path'] if params['path'] else PATH_DEFAULT

    try:

        # Check preflight
        err, version = cfe.check_file_exec(path, '-v')

        # Run preflight
        if err is None:
            err, steps = run_preflight(domain, username, password, servers,
                                       timeout, timesync, extra_args, path)

    except Exception:
        tb = traceback.format_exc()
        err = str(tb)

    # Build result
    result['changed'] = False  # preflight never makes any changes to the host
    result['failed'] = err is not None
    result['msg'] = err if err is not None else ''

    # Create ansible_facts data
    if facts:
        result_facts = result.copy()
        result_facts['params'] = params
        result_facts['version'] = version
        if facts_verbose:
            result_facts['steps'] = steps
        result['ansible_facts'] = {facts_key: result_facts}

    # Return
    return err, result
def run_normal(params, result):
    """
    Normal mode logic.

    params contains input parameters.

    result contains run results skeleton, will modify/add to and then return
    this value along with an err value that contains None if no error or a string
    describing the error.
    """

    # Return data
    err = None
    version = ''
    users_allowed = []

    # Parameters
    user_name = params['user_name'] if params[
        'user_name'] else USER_NAME_DEFAULT
    facts = params['facts']
    facts_key = params['facts_key'] if params[
        'facts_key'] else FACTS_KEY_DEFAULT

    try:

        # Check vastool
        err, version = cfe.check_file_exec(vt.VASTOOL_PATH, '-v')

        # Run vastool
        if err is None:
            err, users_allowed = run_vastool_list_users_allowed()

        if user_name:
            users_allowed = [
                user for user in users_allowed if user[0] == user_name
            ]

    except Exception:
        tb = traceback.format_exc()
        err = str(tb)

    # Build result
    result[
        'changed'] = False  # vastool list users-allowed never makes any changes to the host
    result['failed'] = err is not None
    result['msg'] = err if err is not None else ''

    # Create ansible_facts data
    if facts:
        result_facts = result.copy()
        result_facts['params'] = params
        result_facts['version'] = version
        result_facts['users_allowed'] = users_allowed
        result['ansible_facts'] = {facts_key: result_facts}

    # Return
    return err, result
def run_normal(params, result):
    """
    Normal mode logic.

    params contains input parameters.

    result contains run results skeleton, will modify/add to and then return
    this value along with an err value that contains None if no error or a string
    describing the error.
    """

    # Return data
    err = None
    version = ''
    issues = []

    # Parameters
    facts = params['facts']
    facts_verbose = params['facts_verbose']
    facts_key = params['facts_key'] if params[
        'facts_key'] else FACTS_KEY_DEFAULT

    try:

        # Check vastool
        err, version = cfe.check_file_exec(vt.VASTOOL_PATH, '-v')

        # Run vastool
        if err is None:
            err, issues = run_vastool_status()

    except Exception:
        tb = traceback.format_exc()
        err = str(tb)

    # Build result
    result[
        'changed'] = False  # vastool status never makes any changes to the host
    result['failed'] = err is not None
    result['msg'] = err if err is not None else ''

    # Create ansible_facts data
    if facts:
        result_facts = result.copy()
        result_facts['params'] = params
        result_facts['version'] = version
        if facts_verbose:
            result_facts['issues'] = issues
        result['ansible_facts'] = {facts_key: result_facts}

    # Return
    return err, result
def run_normal(params, result):
    """
    Normal mode logic.

    params contains input parameters.

    result contains run results skeleton, will modify/add to and then return
    this value along with an err value that contains None if no error or a string
    describing the error.
    """

    # Return data
    err = None
    version = ''
    mapped_users = []
    gecos_of_users = {}

    # Parameters
    facts = params['facts']
    facts_key = params['facts_key'] if params[
        'facts_key'] else FACTS_KEY_DEFAULT

    try:

        while True:
            err, version = cfe.check_file_exec(vt.VASTOOL_PATH, '')
            if err is not None:
                break

            status_domain = vt.vastool_status()
            if status_domain is None:
                break

            err, version = cfe.check_file_exec(ASDCOM_PATH, '')
            if err is not None:
                break

            err, mapped_users = run_asdcom_getmappedusers()
            if err is not None:
                break

            if platform.system() == 'Darwin':
                rc, rval_str = run_dscl('. -list /Users')
                if rc == 0:
                    list_of_users = rval_str.splitlines()
                    for user in list_of_users:
                        gecos = get_user_property(user, 'RealName')
                        gecos_of_users[user] = gecos
                else:
                    err = 'Failed to get list of users. ' + rval_str
            else:
                with open('/etc/passwd', 'rb') as passwd_file:
                    passwd_bytes = passwd_file.read()
                    passwd_str = to_text(passwd_bytes,
                                         errors='surrogate_or_strict')

                    local_unix_users = passwd_str.split('\n')
                    local_unix_users = [
                        user.strip() for user in local_unix_users
                    ]
                    local_unix_users = [
                        user for user in local_unix_users if len(user) > 0
                    ]
                    local_unix_users = [
                        user for user in local_unix_users if user[0] != '#'
                    ]
                    local_unix_users = [
                        user.split(':') for user in local_unix_users
                    ]
                    local_unix_users = [
                        user for user in local_unix_users if len(user) == 7
                    ]

                for user in local_unix_users:
                    gecos_of_users[user[0]] = user[4]

            for mapped_user in mapped_users:
                if mapped_user[0] in gecos_of_users:
                    mapped_user.append(gecos_of_users[mapped_user[0]])

            break

    except Exception:
        tb = traceback.format_exc()
        err = str(tb)

    # Build result
    result[
        'changed'] = False  # this module never makes any changes to the host
    result['failed'] = err is not None
    result['msg'] = err if err is not None else ''

    # Create ansible_facts data
    if facts:
        result_facts = result.copy()
        result_facts['params'] = params
        result_facts['local_unix_users_with_ad_logon'] = mapped_users
        result['ansible_facts'] = {facts_key: result_facts}

    # Return
    return err, result
Example #5
0
def run_normal(params, result):
    """
    Normal mode logic.

    params contains input parameters.

    result contains run results skeleton, will modify/add to and then return
    this value along with an err value that contains None if no error or a string
    describing the error.
    """

    # Return data
    err = None
    version = ''
    users_allow = []
    users_deny = []

    # Parameters
    facts = params['facts']
    facts_key = params['facts_key'] if params[
        'facts_key'] else FACTS_KEY_DEFAULT

    try:

        # Check vastool
        err, version = cfe.check_file_exec(vt.VASTOOL_PATH, '-v')

        # Run vastool
        if err is None:
            err, users_allow_file = run_vastool_inspect(
                'vas_auth users-allow-file')

        if err is None:
            err, users_deny_file = run_vastool_inspect(
                'vas_auth users-deny-file')

        if err is None:
            if not users_allow_file:
                users_allow_file = '/etc/opt/quest/vas/users.allow'
            if not users_deny_file:
                users_deny_file = '/etc/opt/quest/vas/users.deny'

        if err is None:
            err, users_allow = get_entries(users_allow_file)

        if err is None:
            err, users_deny = get_entries(users_deny_file)

    except Exception:
        tb = traceback.format_exc()
        err = str(tb)

    # Build result
    result[
        'changed'] = False  # this module never makes any changes to the host
    result['failed'] = err is not None
    result['msg'] = err if err is not None else ''

    # Create ansible_facts data
    if facts:
        result_facts = result.copy()
        result_facts['params'] = params
        result_facts['version'] = version
        result_facts['users_allow'] = users_allow
        result_facts['users_deny'] = users_deny
        result['ansible_facts'] = {facts_key: result_facts}

    # Return
    return err, result
def run_normal(params, result):
    """
    Normal mode logic.

    params contains input parameters.

    result contains run results skeleton, will modify/add to and then return
    this value along with an err value that contains None if no error or a string
    describing the error.
    """

    # Return data
    err = None
    version = ''
    changed = False
    steps = []

    # Parameters
    state = params['state']
    domain = params['domain']
    username = params['username']
    password = params['password']
    servers = params['servers']
    account_name = params['account_name']
    account_container = params['account_container']
    extra_args = params['extra_args']
    facts = params['facts']
    facts_verbose = params['facts_verbose']
    facts_key = params['facts_key'] if params[
        'facts_key'] else FACTS_KEY_DEFAULT

    try:

        # Check vastool
        err, version = cfe.check_file_exec(vt.VASTOOL_PATH, '-v')

        # Run vastool
        if err is None:
            err, changed, steps = run_vastool(state, domain, username,
                                              password, servers, account_name,
                                              account_container, extra_args)

    except Exception:
        tb = traceback.format_exc()
        err = str(tb)

    # Build result
    result['changed'] = changed
    result['failed'] = err is not None
    result['msg'] = err if err is not None else ''

    # Create ansible_facts data
    if facts:
        result_facts = result.copy()
        result_facts['params'] = params
        result_facts['version'] = version
        if facts_verbose:
            result_facts['steps'] = steps
        result['ansible_facts'] = {facts_key: result_facts}

    # Return
    return err, result