- name: install SeaDrive chocolatey.chocolatey.win_chocolatey: name: seadrive state: latest register: install_result # determine installation location - name: search for SeaDrive installation folder in Program Files win_stat: path: "{{ ansible_env.ProgramFiles }}\\SeaDrive\\bin" get_checksum: no register: seadrive_stat - name: fail if SeaDrive is missing fail: msg: "SeaDrive is missing from this system" when: not seadrive_stat.stat.exists - name: get SeaDrive installation location set_fact: sd_install_folder: "{{ seadrive_stat.stat.path }}" - debug: msg: "SeaDrive is installed to {{ sd_install_folder }}" # clear old per-user autorun entries - set_fact: sd_partial_autorun_path: Software\Microsoft\Windows\CurrentVersion\Run - include_tasks: tasks/get_all_hkus.yml - name: collect all SeaDrive autorun entries in all HKUs win_reg_stat: path: "{{ item }}\\{{ sd_partial_autorun_path }}" loop: "{{ hkus }}" register: sd_autoruns - name: remove all SeaDrive entries in all HKUs win_regedit: path: "{{ item.item }}\\{{ sd_partial_autorun_path }}" name: SeaDrive type: string state: absent when: item.exists and (item.properties['SeaDrive'] is defined) loop: "{{ sd_autoruns.results }}" # setup global autorun - name: set SeaDrive to launch on boot for all users win_regedit: path: HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run name: SeaDrive type: string data: "{{ sd_install_folder }}\\seadrive-gui.exe" state: present # remove default shortcut - name: remove default shortcut win_shortcut: dest: "{{ ansible_env.PUBLIC }}\\Desktop\\SeaDrive.lnk" state: absent # add custom shortcut to root folder - name: run a PSH snippet to get at least one SeaDrive root folder win_shell: | $Path = gci Registry::HKEY_users | ? {$_.Name -notlike "*Classes" -and $_.Name -notlike "*.DEFAULT"} | ` select @{n="SFPath";e={$_.PSPath + "\Software\SeaDrive\Seafile Drive Client\Settings"}} | ? ` {test-path $_.SFPath } | % { (gp $_.SFPath).seadriveRoot } | select -first 1 if ($Path) { $Path = (gci $Path | ? PSIsContainer | select -first 1).FullName if ($Path) { $Path = (gci $Path | ? PSIsContainer | ? Name -like "*groups*" | select -first 1).FullName if ($Path) { Write-Host -NoNewline $Path } } } register: script_output failed_when: script_output.stdout == '' changed_when: false - set_fact: sd_root_folder: '{{ script_output.stdout | replace("/","\;") | replace(";", "") }}' - name: download custom icon to SeaDrive directory win_copy: src: custom_icon_seadrive.ico dest: "{{ sd_install_folder }}\\custom_icon_seadrive.ico" force: yes - name: edit SeaDrive shortcut on the desktop win_shortcut: src: "{{ sd_root_folder }}" dest: "{{ ansible_env.PUBLIC }}\\Desktop\\Файлы {{ org_localized }}.lnk" icon: "{{ sd_install_folder }}\\custom_icon_seadrive.ico" description: "Открыть файловое хранилище {{ org_localized }}" changed_when: False # register custom CSP - name: ensure all required variables are set fail: msg: mandatory variables are not set, cannot add custom CSP when: (sd_install_folder is not defined) or (sd_root_folder is not defined) - name: setup CSP variables set_fact: sd_csp_clsid: "{EE8556E2-2E7E-4909-81BB-0020A484F618}" sd_csp_root: "HKLM:" sd_csp_name: "Файлы {{ org_localized }}" - name: concat CLSID and key to determine the full path to CSP set_fact: sd_csp_path: "{{ sd_csp_root }}\\Software\\Classes\\CLSID\\{{ sd_csp_clsid }}" - name: 1. add CLSID and set CSP name win_regedit: path: "{{ sd_csp_path }}" type: string data: "{{ sd_csp_name }}" - name: 2. set the icon for CSP win_regedit: path: "{{ sd_csp_path }}\\DefaultIcon" type: expandstring name: "" data: "{{ sd_install_folder }}\\custom_icon_seadrive.ico" - name: 3. pin CSP to namespace tree win_regedit: path: "{{ sd_csp_path }}" type: dword name: System.IsPinnedToNameSpaceTree data: 1 - name: 4. set location (sort order) for CSP win_regedit: path: "{{ sd_csp_path }}" type: dword name: SortOrderIndex data: 0x42 - name: 5. provide DLL for CSP that hosts the extension win_regedit: path: "{{ sd_csp_path }}\\InProcServer32" type: expandstring name: "" data: "%SystemRoot%\\system32\\shell32.dll" - name: 6. define the instance object win_regedit: path: "{{ sd_csp_path }}\\Instance" type: string name: CLSID data: "{0E5AAE11-A475-4c5b-AB00-C66DE400274E}" - name: 7. set FS attributes on CSP folder win_regedit: path: "{{ sd_csp_path }}\\Instance\\InitPropertyBag" type: dword name: Attributes data: 17 - name: 8. set path to system root win_regedit: path: "{{ sd_csp_path }}\\Instance\\InitPropertyBag" type: expandstring name: TargetFolderPath data: "{{ sd_root_folder }}" - name: 9. set shell flags win_regedit: path: "{{ sd_csp_path }}\\ShellFolder" type: dword name: FolderValueFlags data: 0x28 - name: 10. set SFGAO flags win_regedit: path: "{{ sd_csp_path }}\\ShellFolder" type: dword name: Attributes data: 0xF080004D - name: 11. register CSP in namespace root win_regedit: path: "{{ sd_csp_root }}\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Desktop\\NameSpace\\{{ sd_csp_clsid }}" type: string data: "{{ sd_csp_name }}" - name: 12. hide CSP from desktop folder win_regedit: path: "{{ sd_csp_root }}\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\HideDesktopIcons\\NewStartPanel" type: dword name: "{{ sd_csp_clsid }}" data: 1