get_url - Downloads files from HTTP, HTTPS, or FTP to node

Synopsis

  • Downloads files from HTTP, HTTPS, or FTP to the remote server. The remote server must have direct access to the remote resource.
  • By default, if an environment variable <protocol>_proxy is set on the target host, requests will be sent through that proxy. This behaviour can be overridden by setting a variable for this task (see setting the environment), or by using the use_proxy option.
  • HTTP redirects can redirect from HTTP to HTTPS so you should be sure that your proxy environment for both protocols is correct.
  • From Ansible 2.4 when run with --check, it will do a HEAD request to validate the URL but will not download the entire file or verify it against hashes.
  • For Windows targets, use the win_get_url module instead.

Options

parameter required default choices comments
attributes
(added in 2.3)
no None
Attributes the file or directory should have. To get supported flags look at the man page for chattr on the target system. This string should contain the attributes in the same order as the one displayed by lsattr.
aliases: attr
backup
(added in 2.1)
no no
  • yes
  • no
Create a backup file including the timestamp information so you can get the original file back if you somehow clobbered it incorrectly.
checksum
(added in 2.0)
no
If a 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. Format: <algorithm>:<checksum>, e.g. checksum="sha256:D98291AC[...]B6DC7B97"
If you worry about portability, only the sha1 algorithm is available on all platforms and python versions.
The third party hashlib library can be installed for access to additional algorithms.
Additionally, if a checksum is passed to this parameter, and the file exist under the dest location, the destination_checksum would be calculated, and if checksum equals destination_checksum, the file download would be skipped (unless force is true).
client_cert
(added in 2.4)
no
PEM formatted certificate chain file to be used for SSL client authentication. This file can also include the key as well, and if the key is included, client_key is not required.
client_key
(added in 2.4)
no
PEM formatted file that contains your private key to be used for SSL client authentication. If client_cert contains both the certificate and key, this option is not required.
dest
yes
Absolute path of where to download the file to.
If dest is a directory, either the server provided filename or, if none provided, the base name of the URL on the remote server will be used. If a directory, force has no effect.
If dest is a directory, the file will always be downloaded (regardless of the force option), but replaced only if the contents changed..
force
no no
  • yes
  • no
If yes and dest is not a directory, will download the file every time and replace the file if the contents change. If no, the file will only be downloaded if the destination does not exist. Generally should be yes only for small local files.
Prior to 0.6, this module behaved as if yes was the default.
aliases: thirsty
force_basic_auth
(added in 2.0)
no no
  • yes
  • no
httplib2, the library used by the uri module only sends authentication information when a webservice responds 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 initial request.
group
no
Name of the group that should own the file/directory, as would be fed to chown.
headers
(added in 2.0)
no
Add custom HTTP headers to a request in the format "key:value,key:value".
mode
no
Mode the file or directory should be. For those used to /usr/bin/chmod remember that modes are actually octal numbers (like 0644). Leaving off the leading zero will likely have unexpected results. As of version 1.8, the mode may be specified as a symbolic mode (for example, u+rwx or u=rw,g=r,o=r).
others
no
all arguments accepted by the file module also work here
owner
no
Name of the user that should own the file/directory, as would be fed to chown.
selevel
no s0
Level part of the SELinux file context. This is the MLS/MCS attribute, sometimes known as the range. _default feature works as for seuser.
serole
no
Role part of SELinux file context, _default feature works as for seuser.
setype
no
Type part of SELinux file context, _default feature works as for seuser.
seuser
no
User part of SELinux file context. Will default to system policy, if applicable. If set to _default, it will use the user portion of the policy if available.
sha256sum
(added in 1.3)
no
If a SHA-256 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 is deprecated. Use checksum instead.
timeout
(added in 1.8)
no 10
Timeout in seconds for URL request.
tmp_dest
(added in 2.1)
no
Absolute path of where temporary file is downloaded to.
Defaults to TMPDIR, TEMP or TMP env variables or a platform specific value.
unsafe_writes
(added in 2.2)
no
  • yes
  • no
Normally this module uses atomic operations to prevent data corruption or inconsistent reads from the target files, sometimes systems are configured or just broken in ways that prevent this. One example are docker mounted files, they cannot be updated atomically and can only be done in an unsafe manner.
This boolean option allows ansible to fall back to unsafe methods of updating files for those cases in which you do not have any other choice. Be aware that this is subject to race conditions and can lead to data corruption.
url
yes
HTTP, HTTPS, or FTP URL in the form (http|https|ftp)://[user[:pass]]@host.domain[:port]/path
url_password
(added in 1.6)
no
The password for use in HTTP basic authentication.
If the url_username parameter is not specified, the url_password parameter will not be used.
url_username
(added in 1.6)
no
The username for use in HTTP basic authentication.
This parameter can be used without url_password for sites that allow empty passwords.
use_proxy
no yes
  • yes
  • no
if no, it will not use a proxy, even if one is defined in an environment variable on the target hosts.
validate_certs
no yes
  • yes
  • no
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates.

Examples

- name: Download foo.conf
  get_url:
    url: http://example.com/path/file.conf
    dest: /etc/foo.conf
    mode: 0440

- name: Download file and force basic auth
  get_url:
    url: http://example.com/path/file.conf
    dest: /etc/foo.conf
    force_basic_auth: yes

- name: Download file with custom HTTP headers
  get_url:
    url: http://example.com/path/file.conf
    dest: /etc/foo.conf
    headers: 'key:value,key:value'

- name: Download file with check (sha256)
  get_url:
    url: http://example.com/path/file.conf
    dest: /etc/foo.conf
    checksum: sha256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c

- name: Download file with check (md5)
  get_url:
    url: http://example.com/path/file.conf
    dest: /etc/foo.conf
    checksum: md5:66dffb5228a211e61d6d7ef4a86f5758

- name: Download file from a file path
  get_url:
    url: file:///tmp/afile.txt
    dest: /tmp/afilecopy.txt

Return Values

Common return values are documented here Return Values, the following are the fields unique to this module:

name description returned type sample
backup_file
name of backup file created after download
changed and if backup=yes string /path/to/file.txt.2015-02-12@22:09~
checksum_dest
sha1 checksum of the file after copy
success string 6e642bb8dd5c2e027bf21dd923337cbb4214f827
checksum_src
sha1 checksum of the file
success string 6e642bb8dd5c2e027bf21dd923337cbb4214f827
dest
destination file/path
success string /path/to/file.txt
gid
group id of the file
success int 100
group
group of the file
success string httpd
md5sum
md5 checksum of the file after download
when supported string 2a5aeecc61dc98c4d780b14b330e3282
mode
permissions of the target
success string 0644
msg
the HTTP message from the request
always string OK (unknown bytes)
owner
owner of the file
success string httpd
secontext
the SELinux security context of the file
success string unconfined_u:object_r:user_tmp_t:s0
size
size of the target
success int 1220
src
source file used after download
changed string /tmp/tmpAdFLdV
state
state of the target
success string file
status
the HTTP status code from the request
always int 200
uid
owner id of the file, after execution
success int 100
url
the actual URL used for the request
always string https://www.ansible.com/

Notes

Note

  • For Windows targets, use the win_get_url module instead.

Status

This module is flagged as stableinterface which means that the maintainers for this module guarantee that no backward incompatible interface changes will be made.

Maintenance Info

For more information about Red Hat’s this support of this module, please refer to this knowledge base article<https://access.redhat.com/articles/rhel-top-support-policies>

For help in developing on modules, should you be so inclined, please read Community Information & Contributing, Testing Ansible and Developing Modules.

© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.4/get_url_module.html