import copy


def set_hosts_for_inventory_group(inventory, group, nodes):
  """Set the given list of nodes as hosts for the given group, e.g. 'new_masters' """
  #host entries in the inventory have to be dicts,
  #even when they don't have any values beneath (e.g. "vars:" in ansible inventory)
  group_hosts = { node : None for node in nodes }

  new_inventory = copy.deepcopy(inventory)
  new_inventory['all']['children']['homek8s']['children'][group]['hosts'] = group_hosts
  return new_inventory