Trending September 2023 # How Does Ansible Get_Url Works With Examples? # Suggested October 2023 # Top 16 Popular | Lanphuongmhbrtower.com

Trending September 2023 # How Does Ansible Get_Url Works With Examples? # Suggested October 2023 # Top 16 Popular

You are reading the article How Does Ansible Get_Url Works With Examples? updated in September 2023 on the website Lanphuongmhbrtower.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested October 2023 How Does Ansible Get_Url Works With Examples?

Introduction to Ansible Get_Url Explain the Ansible Get_Url

As we already saw, this is an Ansible module to download files on internet-connected remote machines. But even this small task can involve a lot of possibilities when working in a real environment. The parameters acceptable by this module cover many such possibilities. Also, some parameters have their default values already set, even if they are not mentioned in the playbook. So it becomes more important to learn about such parameters, acceptable values, and default values. Also as return values are as equally important as parameters are. So we will list some important, if not all, parameters of this module.

validate_certs: –acceptable values are yes and no. The default is yes. Used on your controlled sites for self-signed certificate validation before download.

use_proxy: –acceptable values are yes and no. The default is yes. To use a proxy.

tmp_dest: Where the file will be downloaded too.

timeout: Default is 10 seconds. Timeout for URL request.

sha256sum: When it is provided, then the digest of the downloaded file is calculated and checked against it to verify successful download and file integrity.

seuser, serole, setype, selevel: These are used to set the SELinux file context.

owner: Similar to chown, to set the owner of the file.

mode: To set the permission of the target file or directory. A better practice is to use 4 octal numbers inside single quotes to represent the permission like ‘0777’ or ‘0644’.

group: This is used to set the group ownership of a file or directory.

force: Acceptable values are yes and no. Default is no. when this is yes and destination is not a directory but an existing file, then it will replace any existing file if any content looks changed. When it is no, then it will download only when the destination does not exist.

dest: This is the path where the file will get download.

checksum: When provided, the digest of the downloaded file is calculated and checked against it to verify successful download and file integrity. Its format is as below: –

client_cert: This is a pem format certificate chain file for SSL client authentication.

client_key: This is a pem format private key for SSL client authentication.

attributes: To set the attributes of the downloaded file. The acceptable flags are the same as chatter. This can be seen by using

backup: Acceptable values are yes and no. To create a backup of an existing file in case of replacing

Also, please have a look on the below return values. This will make you understand the output when you have executed the playbook in verbose mode.

url: Requested URL.

uid: Owner id of file.

status_code: HTTP status code.

state: State of the target.

src: The source file which is used after download.

size: Downloaded file size.

secontext: SELinux security context

owner: File owner.

msg: HTTP request message.

mode: File permission.

md5sum: After download md5 checksum.

group: File’ s group ownership.

gid: File gid.

elapsed: Time elapsed from start to end.

checksum_src: Sha1sum of the file at the source.

checksum_dest: Sha1sum of the file at the destination.

dest: Path where downloaded.

backup_file: Backup file name if any created.

How Does Ansible Get_Url Works?

Ansible get_url module can be used on the command line with ansible command, or it can be mentioned in playbooks which are then executed by the ansible-playbook command. This module has similar syntax like other Ansible modules; a sample is given below: –

Examples of Ansible Get_Url

Now by using examples, we will try to learn about the Ansible file module, which you might have to use in day-to-day operations. We will take some examples, but before going there, we first understand our lab, we used for testing purpose which contains an ansible-controller and two targets named host-one and host-two. Then, we will create playbooks and run Ansible commands on the ansible-controller node and see the results on remote hosts.

Example #1

Here we have a playbook like below, where we are simply trying to download a file from the internet on remote machines.

Code:

mode: ‘0755’

ansible-playbook ansible_get_url.yaml -vv

Example #2

In this example, we have a playbook like below where we are checking sha256sum and set the owner, group, and permission for the downloaded file.

Code:

checksum: sha256:B76A8EEA8F48EA317507990E323DA3602F683EDB2D71935E761F0EC12114B711

Output:

Also, we shall check the downloaded file on target hosts, to do this, we can run a for loop lie below:

for i in {host-one,host-two}; do ssh $i "hostname;ls -l /var/tmp/vim-minimal-7.4.629-6.el7.x86_64.rpm";done

Output:

Conclusion

As we saw in this article, Ansible get_url is an important module, especially when your remote target machines are connected to the internet and your needs, be it documents, configuration file software packages, are available online only. So you should have good knowledge of it, at least what are possibilities when using it. So learn it first and then use it.

Recommended Articles

This is a guide to Ansible get_url. Here we discuss How Does Ansible Get_Url Works and Examples along with codes and outputs. You may also have a look at the following articles to learn more –

You're reading How Does Ansible Get_Url Works With Examples?

Update the detailed information about How Does Ansible Get_Url Works With Examples? on the Lanphuongmhbrtower.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!