def _add_module_to_zip(zf, remote_module_fqn, b_module_data):
    """Add a module from ansible or from an ansible collection into the module zip"""
    module_path_parts = remote_module_fqn.split('.')
    module_path = '/'.join(module_path_parts) + '.py'
    zf.writestr(module_path, b_module_data)
    if module_path_parts[0] == 'ansible':
        start = 2
        existing_paths = frozenset()
    else:
        start = 1
        existing_paths = frozenset(zf.namelist())
    for idx in range(start, len(module_path_parts)):
        package_path = '/'.join(module_path_parts[:idx]) + '/__init__.py'
        if package_path in existing_paths:
            continue
        zf.writestr(package_path, b'')
