code: def get_ansible_groups(group_map):
      
      # Some of this logic is cribbed from
      # ansible.inventory.script.InventoryScript
      all_hosts = {}
      group_all = Group('all')
      groups = [group_all]
      for gname, hosts in group_map.iteritems():
          g = Group(gname)
          for host in hosts:
              h = all_hosts.get(host, Host(host))
              all_hosts[host] = h
              g.add_host(h)
              group_all.add_host(h)
          group_all.add_child_group(g)
          groups.append(g)
      return groups
docs: Constructs a list of :class:`ansible.inventory.group.Group` objects from a
      map of lists of host strings.