Using get_url or uri - substitute for curl?

Hello,
I have been searching for a way to use ansible to find a file on a remote host that is accessible via http.
I have a bash script that uses curl to connect to the http addr, and look for a *.iso file.
If it finds the file, it breaks it up using awk, etc to get the file info. the file is named
errata-20200506.iso - i.e. errata is returned, and the date is returned from the file name - but the file is
not downloaded unless it is newer than a file on the local server. if the iso file is newer, it downloads it
to the local server.

I would like to find a way to do this with ansible/yaml - I have used get_url, but I have to specify the file name
I cannot parse the file for date etc before it downloads, etc.

How can I do this in yaml?

Thanks so much,

ewholz
Ansible beginner

With a bit of work, you can use the “uri:” module like this:

---
- name: Test getting web page
hosts: localhost
gather_facts: false

tasks:
- name: Get web information
uri:
url: https://releases.ansible.com/ansible/
return_content: true
register: web_files

- name: Show just the content
debug:
msg: "Here is the file: {{ web_files.content }}"

- name: Show each element
debug:
msg: "An item: {{ item }}"
loop: "{{ web_files.content.splitlines() }}"
loop_control:
label: ""

For your use, the key is the “return_content: true” flag then parsing it out of the registered “web_files” variable.

The first task “Show just the content” shows all the raw HTML text returned.

The second task loop over each of those lines - you will have to put in more Jinja2 code to parse out the file names, but this would permit you to do some checks before downloading the much larger ISO.