<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _parse_hostvar_dir(self, inventory_path):
 """ Parse host_vars dir, if it exists. """

        # inventory_path could point to a `hosts` file, or to a dir. So we
        # construct the location to the `host_vars` differently.
        if os.path.isdir(inventory_path):
            path = os.path.join(inventory_path, 'host_vars')
        else:
            path = os.path.join(os.path.dirname(inventory_path), 'host_vars')

        self.log.debug("Parsing host vars (dir): {0}".format(path))
        if not os.path.exists(path):
            self.log.info("No such dir {0}".format(path))
            return

        for entry in os.listdir(path):
            # Skip .git folder
            if entry == '.git':
                continue
            full_path = os.path.join(path, entry)

            # file or dir name is the hostname
            hostname = strip_exts(entry, ('.yml', '.yaml', '.json'))

            if os.path.isfile(full_path):
                # Parse contents of file as host vars.
                self._parse_hostvar_file(hostname, full_path)
            elif os.path.isdir(full_path):
                # Parse each file in the directory as a file containing
                # variables for the host.
                for file_entry in os.listdir(full_path):
                    p = os.path.join(full_path, file_entry)
                    if not os.path.isdir(p):
                        self._parse_hostvar_file(hostname, p)