0

I have a task that looks like this:

- name: Download {{ mysql_connector_download_url }}
  ansible.builtin.get_url:
    url: '{{ mysql_connector_download_url }}'
    dest: '{{ mysql_connector_download_dir }}/{{ mysql_connector_download_file }}'
  register: jdbc_driver

where mysql_connector_download_url expands to https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-j-8.0.31.tar.gz

This has worked for quite a while but for some reason it does not anymore and the error I get is this:

    "msg": "Request failed",
    "response": "HTTP Error 403: Forbidden",
    "status_code": 403,
    "url": "https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-j-8.0.31.tar.gz"

The odd thing is that I can type wget and the same URL on the target machine and that works fine, it is only through ansible this download fails.

I was thinking that perhaps cookies are involved but if that was the case, should not the wget fail as well?

koenig
  • 125
  • 8
  • It's probably a matter of user agent. What if you try wget with User-Agent ansible-httpget? – A. Darwin Jan 25 '23 at 20:52
  • So I tried `wget -U "ansible-httpget" https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-j-8.0.31.tar.gz` on the target and that worked just fine. :-( – koenig Jan 27 '23 at 21:20
  • This is probably related to the 302 redirection. Pointing to the redirected url (i.e. https://cdn.mysql.com//Downloads/Connector-J/mysql-connector-j-8.0.31.tar.gz) fixes the issue. It should work with the redirection though... – Zeitounator Feb 02 '23 at 15:22
  • I was thinking about that possibility but I had no idea as to how to get the redirected URL. Thank you for that suggestion -- I will try it out presently – koenig Feb 02 '23 at 15:26
  • `I had no idea as to how to get the redirected URL` <= one solution is to just read the wget output when you download manually from the original uri. – Zeitounator Feb 03 '23 at 23:26
  • Ah, I've never payed much attention to that output. Bad choice. Live and learn. Thank you! – koenig Feb 06 '23 at 09:10

1 Answers1

1

Since the file is available but hidden behind a a redirection it turned out that the easiest way is to look at the output from wget to get the file's real location and download it from there.

In this case redirects https://dev.mysql.com/get/Downloads… to https://cdn.mysql.com/Downloads… and passing that last URL to Ansible was successful.

This might of course change in the future but this solution solved the problem for me.

koenig
  • 125
  • 8