'Helper function to add a new host to inventory based on a task result.'

def _add_host(self, host_info, iterator):

    if host_info:
        host_name = host_info.get('host_name')
        if (host_name not in self._inventory.hosts):
            self._inventory.add_host(host_name, 'all')
        new_host = self._inventory.hosts.get(host_name)
        new_host.vars = combine_vars(new_host.get_vars(), host_info.get('host_vars', dict()))
        new_groups = host_info.get('groups', [])
        for group_name in new_groups:
            if (group_name not in self._inventory.groups):
                self._inventory.add_group(group_name)
            new_group = self._inventory.groups[group_name]
            new_group.add_host(self._inventory.hosts[host_name])
        self._inventory.clear_pattern_cache()
        self._inventory.reconcile_inventory()
