1
$ ansible --version
ansible 2.10.8

I have a Linux Ansible server, and a Windows target host. I'm trying to setup a task to download from a secure FTP (SFTP) server. The only module I can find is win_get_url, but it says nothing about SFTP support. I tried it anyway

- name: Download from SFTP
  win_get_url:
    url: "sftp://ftp.mycompany.com/path/someFile.exe"
    dest: "C:\\temp"
    url_username: "myUser"
    utl_password: "myPw123"

But I get

TASK [downloader : Download sftp://ftp.kmhapub.com/devops/exa-3rdparty/7z/7z2107-x64.exe] *************************************************
task path: /path/exa-playbooks/roles/downloader/tasks/download.yml:2
redirecting (type: modules) ansible.builtin.win_get_url to ansible.windows.win_get_url
Using module file /usr/local/Cellar/ansible/3.3.0/libexec/lib/python3.9/site-packages/ansible_collections/ansible/windows/plugins/modules/win_get_url.ps1
Pipelining is enabled.
<10.227.x.x> ESTABLISH WINRM CONNECTION FOR USER: Administrator on PORT 5986 TO 10.227.x.x
EXEC (via pipeline wrapper)
The full traceback is:
Exception calling "Create" with "1" argument(s): "The URI prefix is not recognized."
At line:213 char:20
+ ... $web_request = Get-AnsibleWindowsWebRequest -Uri $Uri -Module $Module
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-AnsibleWindowsWebRequest], MethodInvocationException
    + FullyQualifiedErrorId : NotSupportedException,Get-AnsibleWindowsWebRequest

ScriptStackTrace:
at Get-AnsibleWindowsWebRequest, <No file>: line 211
at Invoke-DownloadFile, <No file>: line 213
at <ScriptBlock>, <No file>: line 265

System.Management.Automation.MethodInvocationException: Exception calling "Create" with "1" argument(s): "The URI prefix is not recognized." ---> System.NotSupportedException: The URI prefix is not recognized.
   at System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase)
   at CallSite.Target(Closure , CallSite , Type , Object )
   --- End of inner exception stack trace ---
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
   at System.Management.Automation.PSScriptCmdlet.RunClause(Action`1 clause, Object dollarUnderbar, Object inputToProcess)
   at System.Management.Automation.PSScriptCmdlet.DoEndProcessing()
   at System.Management.Automation.CommandProcessorBase.Complete()
fatal: [10.227.x.x]: FAILED! => {
    "changed": false,
    "msg": "Unhandled exception while executing module: Exception calling \"Create\" with \"1\" argument(s): \"The URI prefix is not recognized.\""
}

PLAY RECAP ********************************************************************************************************************************
10.227.x.x               : ok=5    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

What does the error mean, and can it be fixed? Or is there a different module for downloading from an SFTP server? TIA

Chris F
  • 14,337
  • 30
  • 94
  • 192

1 Answers1

1

It already tells you what the Problem is "The URI prefix is not recognized"

When you take a look at the documentation of win_get_url you see, that SFTP is not mentioned in the supported Protocols (HTTP, HTTPS, FTP), probably because it is not supported by that module. if you look into the code, they also check if the URI ist one of those. So it seems like, it is really not supported

Also, if you want to censor the IP-Adresse of you Server, you should do that in all of your code, not just at the end ;)