code: def _parse_fact_dir(self, fact_dir, fact_cache=False):
          
          self.log.debug("Parsing fact dir: {0}".format(fact_dir))
          if not os.path.isdir(fact_dir):
              raise IOError("Not a directory: '{0}'".format(fact_dir))
  
          flist = []
          for (dirpath, dirnames, filenames) in os.walk(fact_dir):
              flist.extend(filenames)
              break
  
          for fname in flist:
              if fname.startswith('.'):
                  continue
              self.log.debug("Reading host facts from {0}".format(os.path.join(fact_dir, fname)))
              hostname = fname
  
              fd = codecs.open(os.path.join(fact_dir, fname), 'r', encoding='utf8')
              s = fd.readlines()
              fd.close()
              try:
                  x = json.loads(''.join(s))
                  # for compatibility with fact_caching=jsonfile
                  # which omits the "ansible_facts" parent key added by the setup module
                  if fact_cache:
                      x = json.loads('{ "ansible_facts": ' + ''.join(s) + ' }')
                  self.update_host(hostname, x)
                  self.update_host(hostname, {'name': hostname})
              except ValueError as e:
                  # Ignore non-JSON files (and bonus errors)
                  self.log.warning("Error parsing: %s: %s" % (fname, e))
docs: Walk through a directory of JSON files and extract information from
          them. This is used for both the Ansible fact gathering (setup module)
          output and custom variables.