- name: Initial setup on host hosts: win gather_facts: no tasks: - name: Remove old files # kill all running rclone and silentcmd instances, delete c:\rclone fully, create c:\rclone and c:\rclone\cache dirs ansible.windows.win_powershell: script: | Get-Process "rclone" | Stop-Process -Force Get-Process "silentcmd" | Stop-Process -Force Remove-Item "C:\rclone" -Recurse -Force New-Item -Path "c:\" -Name "rclone" -ItemType "directory" New-Item -Path "c:\rclone\" -Name "cache" -ItemType "directory" $Ansible.Failed = $false - name: Download silentCMD # download silentcmd - small utility which allows to run shell commands without showing nasty black window ansible.windows.win_get_url: url: https://github.com/stbrenner/SilentCMD/releases/download/v1.4/SilentCMD.zip dest: c:\rclone\silentcmd.zip - name: Unzip silentCMD # unzip and remove archive community.windows.win_unzip: src: c:\rclone\silentcmd.zip dest: c:\rclone delete_archive: yes - name: Download rclone # download latest rclone ansible.windows.win_get_url: url: https://downloads.rclone.org/rclone-current-windows-amd64.zip dest: c:\rclone\rclone.zip - name: Unzip rclone # unzip and remove archive community.windows.win_unzip: src: c:\rclone\rclone.zip dest: c:\rclone delete_archive: yes - name: Locate executable # find main exe and save its path to variable win_find: paths: - C:\rclone patterns: [ 'rclone.exe' ] recurse: yes register: rclone_found - name: Move rclone and create config # powershell-> # save directory path were rclone.exe is stored # move rclone.exe to c:\rclone # delete post archive direcotry # create c:\rclone\rclone.conf file # fill rclone.conf file with settings - this needs to be customized ansible.windows.win_powershell: script: | $PP = (Split-Path -parent "{{ rclone_found.files[0].path }}") Move-Item "{{ rclone_found.files[0].path }}" c:\rclone\ Remove-Item $PP -recurse -force New-Item -Path C:\rclone\ -Name "rclone.conf" -ItemType "file" Add-Content -Path c:\rclone\rclone.conf -Value 'Here goes Line 1 of Your config file' Add-Content -Path c:\rclone\rclone.conf -Value 'Here goes Line 2 of Your config file' Add-Content -Path c:\rclone\rclone.conf -Value '...' $Ansible.Failed = $false - name: Install WinFSP #use choco to install needed driver (more on choco here: https://chocolatey.org/) win_chocolatey: name: winfsp state: present - name: run rclone task on logon # create task in windows task scheduler which will be executed on each user logon event # with usage of silentcmd start rclone with proper parameters # for sure arguments needs to be customized community.windows.win_scheduled_task: name: RCLONE triggers: - type: logon actions: - path: c:\rclone\silentcmd arguments: 'c:\rclone\rclone.exe mount pcloud:/ X: --config c:\rclone\rclone.conf --cache-dir .\cache\ --volname pCloud --vfs-cache-mode writes' working_directory: c:\rclone\ group: użytkownicy state: present multiple_instances: 0 enabled: yes stop_if_going_on_batteries: no