ansible.windows.win_get_url (2.3.0) — module

Downloads file from HTTP, HTTPS, or FTP to node

Authors: Paul Durivage (@angstwad), Takeshi Kuramochi (@tksarah)

Install collection

Install with ansible-galaxy collection install ansible.windows:==2.3.0


Add to requirements.yml

  collections:
    - name: ansible.windows
      version: 2.3.0

Description

Downloads files from HTTP, HTTPS, or FTP to the remote server.

The remote server I(must) have direct access to the remote resource.

For non-Windows targets, use the M(ansible.builtin.get_url) module instead.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Download earthrise.jpg to specified path
  ansible.windows.win_get_url:
    url: http://www.example.com/earthrise.jpg
    dest: C:\Users\RandomUser\earthrise.jpg
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Download earthrise.jpg to specified path only if modified
  ansible.windows.win_get_url:
    url: http://www.example.com/earthrise.jpg
    dest: C:\Users\RandomUser\earthrise.jpg
    force: false
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Download earthrise.jpg to specified path through a proxy server.
  ansible.windows.win_get_url:
    url: http://www.example.com/earthrise.jpg
    dest: C:\Users\RandomUser\earthrise.jpg
    proxy_url: http://10.0.0.1:8080
    proxy_username: username
    proxy_password: password
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Download file from FTP with authentication
  ansible.windows.win_get_url:
    url: ftp://server/file.txt
    dest: '%TEMP%\ftp-file.txt'
    url_username: ftp-user
    url_password: ftp-password
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Download src with sha256 checksum url
  ansible.windows.win_get_url:
    url: http://www.example.com/earthrise.jpg
    dest: C:\temp\earthrise.jpg
    checksum_url: http://www.example.com/sha256sum.txt
    checksum_algorithm: sha256
    force: True
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Download src with sha256 checksum url
  ansible.windows.win_get_url:
    url: http://www.example.com/earthrise.jpg
    dest: C:\temp\earthrise.jpg
    checksum: a97e6837f60cec6da4491bab387296bbcd72bdba
    checksum_algorithm: sha1
    force: True

Inputs

    
url:
    description:
    - The full URL of a file to download.
    required: true
    type: str

dest:
    description:
    - The location to save the file at the URL.
    - Be sure to include a filename and extension as appropriate.
    required: true
    type: path

force:
    default: true
    description:
    - If C(true), will download the file every time and replace the file if the contents
      change. If C(false), will only download the file if it does not exist or the remote
      file has been modified more recently than the local file.
    - This works by sending an http HEAD request to retrieve last modified time of the
      requested resource, so for this to work, the remote web server must support HEAD
      requests.
    type: bool

headers:
    description:
    - Extra headers to set on the request.
    - This should be a dictionary where the key is the header name and the value is the
      value for that header.
    type: dict

checksum:
    description:
    - If a I(checksum) is passed to this parameter, the digest of the destination file
      will be calculated after it is downloaded to ensure its integrity and verify that
      the transfer completed successfully.
    - This option cannot be set with I(checksum_url).
    type: str

proxy_url:
    description:
    - An explicit proxy to use for the request.
    - By default, the request will use the IE defined proxy unless I(use_proxy) is set
      to C(no).
    type: str

use_proxy:
    default: true
    description:
    - If C(no), it will not use the proxy defined in IE for the current user.
    type: bool

http_agent:
    default: ansible-httpget
    description:
    - Header to identify as, generally appears in web server logs.
    - This is set to the C(User-Agent) header on a HTTP request.
    type: str

url_method:
    aliases:
    - method
    description:
    - The HTTP Method of the request.
    type: str

client_cert:
    description:
    - The path to the client certificate (.pfx) that is used for X509 authentication.
      This path can either be the path to the C(pfx) on the filesystem or the PowerShell
      certificate path C(Cert:\CurrentUser\My\<thumbprint>).
    - The WinRM connection must be authenticated with C(CredSSP) or C(become) is used
      on the task if the certificate file is not password protected.
    - Other authentication types can set I(client_cert_password) when the cert is password
      protected.
    type: str

url_timeout:
    aliases:
    - timeout
    default: 30
    description:
    - Specifies how long the request can be pending before it times out (in seconds).
    - Set to C(0) to specify an infinite timeout.
    type: int

checksum_url:
    description:
    - Specifies a URL that contains the checksum values for the resource at I(url).
    - Like C(checksum), this is used to verify the integrity of the remote transfer.
    - This option cannot be set with I(checksum).
    type: str

url_password:
    description:
    - The password for I(url_username).
    type: str

url_username:
    description:
    - The username to use for authentication.
    type: str

proxy_password:
    description:
    - The password for I(proxy_username).
    type: str

proxy_username:
    description:
    - The username to use for proxy authentication.
    type: str

validate_certs:
    default: true
    description:
    - If C(no), SSL certificates will not be validated.
    - This should only be used on personally controlled sites using self-signed certificates.
    type: bool

follow_redirects:
    choices:
    - all
    - none
    - safe
    default: safe
    description:
    - Whether or the module should follow redirects.
    - C(all) will follow all redirect.
    - C(none) will not follow any redirect.
    - C(safe) will follow only "safe" redirects, where "safe" means that the client is
      only doing a C(GET) or C(HEAD) on the URI to which it is being redirected.
    - When following a redirected URL, the C(Authorization) header and any credentials
      set will be dropped and not redirected.
    type: str

force_basic_auth:
    default: false
    description:
    - By default the authentication header is only sent when a webservice responses to
      an initial request with a 401 status. Since some basic auth services do not properly
      send a 401, logins will fail.
    - This option forces the sending of the Basic authentication header upon the original
      request.
    type: bool

checksum_algorithm:
    choices:
    - md5
    - sha1
    - sha256
    - sha384
    - sha512
    default: sha1
    description:
    - Specifies the hashing algorithm used when calculating the checksum of the remote
      and destination file.
    type: str

maximum_redirection:
    default: 50
    description:
    - Specify how many times the module will redirect a connection to an alternative URI
      before the connection fails.
    - If set to C(0) or I(follow_redirects) is set to C(none), or C(safe) when not doing
      a C(GET) or C(HEAD) it prevents all redirection.
    type: int

client_cert_password:
    description:
    - The password for I(client_cert) if the cert is password protected.
    type: str

use_default_credential:
    default: false
    description:
    - Uses the current user's credentials when authenticating with a server protected
      with C(NTLM), C(Kerberos), or C(Negotiate) authentication.
    - Sites that use C(Basic) auth will still require explicit credentials through the
      I(url_username) and I(url_password) options.
    - The module will only have access to the user's credentials if using C(become) with
      a password, you are connecting with SSH using a password, or connecting with WinRM
      using C(CredSSP) or C(Kerberos with delegation).
    - If not using C(become) or a different auth method to the ones stated above, there
      will be no default credentials available and no authentication will occur.
    type: bool

proxy_use_default_credential:
    default: false
    description:
    - Uses the current user's credentials when authenticating with a proxy host protected
      with C(NTLM), C(Kerberos), or C(Negotiate) authentication.
    - Proxies that use C(Basic) auth will still require explicit credentials through the
      I(proxy_username) and I(proxy_password) options.
    - The module will only have access to the user's credentials if using C(become) with
      a password, you are connecting with SSH using a password, or connecting with WinRM
      using C(CredSSP) or C(Kerberos with delegation).
    - If not using C(become) or a different auth method to the ones stated above, there
      will be no default credentials available and no proxy authentication will occur.
    type: bool

Outputs

checksum_dest:
  description: <algorithm> checksum of the file after the download
  returned: success and dest has been downloaded
  sample: 6e642bb8dd5c2e027bf21dd923337cbb4214f827
  type: str
checksum_src:
  description: <algorithm> checksum of the remote resource
  returned: force=true or dest did not exist
  sample: 6e642bb8dd5c2e027bf21dd923337cbb4214f827
  type: str
dest:
  description: destination file/path
  returned: always
  sample: C:\Users\RandomUser\earthrise.jpg
  type: str
elapsed:
  description: The elapsed seconds between the start of poll and the end of the module.
  returned: always
  sample: 2.1406487
  type: float
msg:
  description: Error message, or HTTP status message from web-server
  returned: always
  sample: OK
  type: str
size:
  description: size of the dest file
  returned: success
  sample: 1220
  type: int
status_code:
  description: HTTP status code
  returned: always
  sample: 200
  type: int
url:
  description: requested url
  returned: always
  sample: http://www.example.com/earthrise.jpg
  type: str

See also