ansible.builtin.get_url module – Downloads files from HTTP, HTTPS, or FTP to node
Note
This module is part of ansible-core
and included in all Ansible
installations. In most cases, you can use the short
module name
get_url
even without specifying the collections keyword.
However, we recommend you use the Fully Qualified Collection Name (FQCN) ansible.builtin.get_url
for easy linking to the
module documentation and to avoid conflicting with other collections that may have
the same module name.
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 and will report incorrect changed status.For Windows targets, use the ansible.windows.win_get_url module instead.
Parameters
Parameter |
Comments |
---|---|
The attributes the resulting filesystem object should have. To get supported flags look at the man page for This string should contain the attributes in the same order as the one displayed by The |
|
Create a backup file including the timestamp information so you can get the original file back if you somehow clobbered it incorrectly. Choices:
|
|
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|url>, for example If you worry about portability, only the sha1 algorithm is available on all platforms and python versions. The Python On systems running in FIPS compliant mode, the Additionally, if a checksum is passed to this parameter, and the file exist under the If the checksum URL requires username and password, Default: |
|
SSL/TLS Ciphers to use for the request. When a list is provided, all ciphers are joined in order with See the OpenSSL Cipher List Format for more details. The available ciphers is dependent on the Python and OpenSSL/LibreSSL versions. |
|
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, |
|
PEM formatted file that contains your private key to be used for SSL client authentication. If |
|
Whether to attempt to decompress gzip content-encoded responses. Choices:
|
|
Absolute path of where to download the file to. If If |
|
If Prior to 0.6, this module behaved as if Choices:
|
|
Force the sending of the Basic authentication header upon initial request. 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. Choices:
|
|
Name of the group that should own the filesystem object, as would be fed to When left unspecified, it uses the current group of the current user unless you are root, in which case it can preserve the previous ownership. |
|
Add custom HTTP headers to a request in hash/dict format. The hash/dict format was added in Ansible 2.6. Previous versions used a The |
|
Header to identify as, generally appears in web server logs. Default: |
|
The permissions the resulting filesystem object should have. For those used to Giving Ansible a number without following either of these rules will end up with a decimal number which will have unexpected results. As of Ansible 1.8, the mode may be specified as a symbolic mode (for example, If If Specifying |
|
Name of the user that should own the filesystem object, as would be fed to When left unspecified, it uses the current user unless you are root, in which case it can preserve the previous ownership. Specifying a numeric username will be assumed to be a user ID and not a username. Avoid numeric usernames to avoid this confusion. |
|
The level part of the SELinux filesystem object context. This is the MLS/MCS attribute, sometimes known as the When set to |
|
The role part of the SELinux filesystem object context. When set to |
|
The type part of the SELinux filesystem object context. When set to |
|
The user part of the SELinux filesystem object context. By default it uses the When set to |
|
Timeout in seconds for URL request. Default: |
|
Absolute path of where temporary file is downloaded to. When run on Ansible 2.5 or greater, path defaults to ansible’s When run on Ansible prior to 2.5, it defaults to https://docs.python.org/3/library/tempfile.html#tempfile.tempdir. |
|
A list of header names that will not be sent on subsequent redirected requests. This list is case insensitive. By default all headers will be redirected. In some cases it may be beneficial to list headers such as Default: |
|
Influence when to use atomic operation to prevent data corruption or inconsistent reads from the target filesystem object. By default this module uses atomic operations to prevent data corruption or inconsistent reads from the target filesystem objects, but sometimes systems are configured or just broken in ways that prevent this. One example is docker mounted filesystem objects, which cannot be updated atomically from inside the container and can only be written in an unsafe manner. This option allows Ansible to fall back to unsafe methods of updating filesystem objects when atomic operations fail (however, it doesn’t force Ansible to perform unsafe writes). IMPORTANT! Unsafe writes are subject to race conditions and can lead to data corruption. Choices:
|
|
HTTP, HTTPS, or FTP URL in the form |
|
The password for use in HTTP basic authentication. If the Since version 2.8 you can also use the |
|
The username for use in HTTP basic authentication. This parameter can be used without Since version 2.8 you can also use the |
|
Use GSSAPI to perform the authentication, typically this is for Kerberos or Kerberos through Negotiate authentication. Requires the Python library gssapi to be installed. Credentials for GSSAPI can be specified with NTLM authentication is not supported even if the GSSAPI mech for NTLM has been installed. Choices:
|
|
Determining whether to use credentials from By default When Choices:
|
|
if Choices:
|
|
If This should only be used on personally controlled sites using self-signed certificates. Choices:
|
Attributes
Attribute |
Support |
Description |
---|---|---|
Support: partial the changed status will reflect comparison to an empty source file |
Can run in check_mode and return changed status prediction without modifying target, if not supported the action will be skipped. |
|
Support: none |
Will return details on what has changed (or possibly needs changing in check_mode), when in diff mode |
|
Platform: posix |
Target OS/families that can be operated against |
Notes
Note
For Windows targets, use the ansible.windows.win_get_url module instead.
See Also
See also
- ansible.builtin.uri
Interacts with webservices.
- ansible.windows.win_get_url
Downloads file from HTTP, HTTPS, or FTP to node.
Examples
- name: Download foo.conf
ansible.builtin.get_url:
url: http://example.com/path/file.conf
dest: /etc/foo.conf
mode: '0440'
- name: Download file and force basic auth
ansible.builtin.get_url:
url: http://example.com/path/file.conf
dest: /etc/foo.conf
force_basic_auth: yes
- name: Download file with custom HTTP headers
ansible.builtin.get_url:
url: http://example.com/path/file.conf
dest: /etc/foo.conf
headers:
key1: one
key2: two
- name: Download file with check (sha256)
ansible.builtin.get_url:
url: http://example.com/path/file.conf
dest: /etc/foo.conf
checksum: sha256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c
- name: Download file with check (md5)
ansible.builtin.get_url:
url: http://example.com/path/file.conf
dest: /etc/foo.conf
checksum: md5:66dffb5228a211e61d6d7ef4a86f5758
- name: Download file with checksum url (sha256)
ansible.builtin.get_url:
url: http://example.com/path/file.conf
dest: /etc/foo.conf
checksum: sha256:http://example.com/path/sha256sum.txt
- name: Download file from a file path
ansible.builtin.get_url:
url: file:///tmp/a_file.txt
dest: /tmp/afilecopy.txt
- name: < Fetch file that requires authentication.
username/password only available since 2.8, in older versions you need to use url_username/url_password
ansible.builtin.get_url:
url: http://example.com/path/file.conf
dest: /etc/foo.conf
username: bar
password: '{{ mysecret }}'
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
name of backup file created after download Returned: changed and if backup=yes Sample: |
|
sha1 checksum of the file after copy Returned: success Sample: |
|
sha1 checksum of the file Returned: success Sample: |
|
destination file/path Returned: success Sample: |
|
The number of seconds that elapsed while performing the download Returned: always Sample: |
|
group id of the file Returned: success Sample: |
|
group of the file Returned: success Sample: |
|
md5 checksum of the file after download Returned: when supported Sample: |
|
permissions of the target Returned: success Sample: |
|
the HTTP message from the request Returned: always Sample: |
|
owner of the file Returned: success Sample: |
|
the SELinux security context of the file Returned: success Sample: |
|
size of the target Returned: success Sample: |
|
source file used after download Returned: always Sample: |
|
state of the target Returned: success Sample: |
|
the HTTP status code from the request Returned: always Sample: |
|
owner id of the file, after execution Returned: success Sample: |
|
the actual URL used for the request Returned: always Sample: |