def _set_users(self, node):
        '''
        Create existing local users.

        <users group="root">
          <user password="$1$wYJUgpM5$RXMMeASDc035eX.NbYWFl0" home="/root" name="root"/>
        </users>

        :param node:
        :return:
        '''
        # Get real local users with the local passwords
        shadow = {}
        with salt.utils.files.fopen('/etc/shadow') as rfh:
            for sh_line in rfh.read().split(os.linesep):
                if sh_line.strip():
                    login, pwd = sh_line.split(":")[:2]
                    if pwd and pwd[0] not in '!*':
                        shadow[login] = {'p': pwd}

        with salt.utils.files.fopen('/etc/passwd') as rfh:
            for ps_line in rfh.read().split(os.linesep):
                if ps_line.strip():
                    ps_line = ps_line.strip().split(':')
                    if ps_line[0] in shadow:
                        shadow[ps_line[0]]['h'] = ps_line[5]
                        shadow[ps_line[0]]['s'] = ps_line[6]
                        shadow[ps_line[0]]['g'] = self._get_user_groups(ps_line[0])

        users_groups = []
        users_node = etree.SubElement(node, 'users')
        for u_name, u_data in shadow.items():
            user_node = etree.SubElement(users_node, 'user')
            user_node.set('password', u_data['p'])
            user_node.set('home', u_data['h'])
            user_node.set('name', u_name)
            users_groups.extend(u_data['g'])
        users_node.set('group', ','.join(users_groups))

        return users_node
def _set_users ( self , node ) : shadow = { } with salt . utils . files . fopen ( '/etc/shadow' ) as rfh : for sh_line in rfh . read ( ) . split ( os . linesep ) : if sh_line . strip ( ) : login , pwd = sh_line . split ( ":" ) [ : 2 ] if pwd and pwd [ 0 ] not in '!*' : shadow [ login ] = { 'p' : pwd } with salt . utils . files . fopen ( '/etc/passwd' ) as rfh : for ps_line in rfh . read ( ) . split ( os . linesep ) : if ps_line . strip ( ) : ps_line = ps_line . strip ( ) . split ( ':' ) if ps_line [ 0 ] in shadow : shadow [ ps_line [ 0 ] ] [ 'h' ] = ps_line [ 5 ] shadow [ ps_line [ 0 ] ] [ 's' ] = ps_line [ 6 ] shadow [ ps_line [ 0 ] ] [ 'g' ] = self . _get_user_groups ( ps_line [ 0 ] ) users_groups = [ ] users_node = etree . SubElement ( node , 'users' ) for u_name , u_data in shadow . items ( ) : user_node = etree . SubElement ( users_node , 'user' ) user_node . set ( 'password' , u_data [ 'p' ] ) user_node . set ( 'home' , u_data [ 'h' ] ) user_node . set ( 'name' , u_name ) users_groups . extend ( u_data [ 'g' ] ) users_node . set ( 'group' , ',' . join ( users_groups ) ) return users_node
Create existing local users.

        <users group="root">
          <user password="$1$wYJUgpM5$RXMMeASDc035eX.NbYWFl0" home="/root" name="root"/>
        </users>

        :param node:
        :return: