get_url fails to download

541 views
Skip to first unread message

Brian Peavey

unread,
Jul 18, 2018, 7:35:57 PM7/18/18
to Ansible Project
Hi,
  I'm trying to download and install Segger JLink tools in an Ubuntu VM.  The relevant portion of my ansible playbook is -

- hosts: fw_dev
  vars:
  - username:      "vagrant"
  - download_dir:  "/home/{{username}}/Downloads"
  - jlink_ver:     "V632h_x86_64"
  - jlink_chk:     "md5:cef479d627f9889a7f5c2cb77ee14877"
.
.
  - block:
    - name: Download SEGGER J-Link
      get_url:
        dest: "{{download_dir}}/JLink_Linux_{{jlink_ver}}.deb"
        checksum: "{{jlink_chk}}"
    - name: Install SEGGER J-Link
      become: true
      apt: 
        deb: "{{download_dir}}/JLink_Linux_{{jlink_ver}}.deb"
        state: present
    rescue:
      - debug:
          msg: "SEGGER J-Link Task Failed"


  The output I get is -
TASK [Download SEGGER J-Link] **************************************************
fatal: [fw_dev]: FAILED! => {"changed": false, "msg": "The checksum for /home/vagrant/Downloads/JLink_Linux_V632h_x86_64.deb did not match cef479d627f9889a7f5c2cb77ee14877; it was d13f645acf61170d3ad5792e8e556750."}

  I've also tried without the checksum, but then I get a lailure on the install due to the package format being incorrect.
  If I use a web browser to go to the url, it takes me to another page asking to accept the license terms before it downloads the package.  How do I handle this using Ansible?
  Thanks...
Brian

Andreas Olsson

unread,
Jul 19, 2018, 1:53:11 AM7/19/18
to ansible...@googlegroups.com
ons 2018-07-18 klockan 16:35 -0700 skrev Brian Peavey:
> ...
> I've also tried without the checksum, but then I get a lailure on
> the install due to the package format being incorrect.
> If I use a web browser to go to the url, it takes me to another
> page asking to accept the license terms before it downloads the
> package. How do I handle this using Ansible?
> Thanks...

What is most likely happening is that Ansible isn't downloading the deb
file, but rather the HTML of the page you are seeing in the browser.

I would suggest that you download the deb file using the browser, where
you are in a position to accept the license terms, etc. Then you put
the deb file somewhere appropriate, and have Ansible install it from
that location instead.

Somewhere appropriate might for example be an internal web server or a
sufficiently restricted S3 bucket.

// Andreas

Kai Stian Olstad

unread,
Jul 19, 2018, 3:19:50 AM7/19/18
to ansible...@googlegroups.com
On 19.07.2018 01:35, Brian Peavey wrote:
> Hi,
> I'm trying to download and install Segger JLink tools in an Ubuntu
> VM.
> The relevant portion of my ansible playbook is -
>
> - hosts: fw_dev
> vars:
> - username: "vagrant"
> - download_dir: "/home/{{username}}/Downloads"
> - jlink_ver: "V632h_x86_64"
> - jlink_chk: "md5:cef479d627f9889a7f5c2cb77ee14877"

You should not have the dash infront of the variables, it's not valid.


> - block:
> - name: Download SEGGER J-Link
> get_url:
> url:
> "https://www.segger.com/downloads/jlink/JLink_Linux_x86_64.deb"
> dest: "{{download_dir}}/JLink_Linux_{{jlink_ver}}.deb"
> checksum: "{{jlink_chk}}"
> - name: Install SEGGER J-Link
> become: true
> apt:
> deb: "{{download_dir}}/JLink_Linux_{{jlink_ver}}.deb"
> state: present
> rescue:
> - debug:
> msg: "SEGGER J-Link Task Failed"
>
>
> I've also tried without the checksum, but then I get a lailure on the
> install due to the package format being incorrect.
> If I use a web browser to go to the url, it takes me to another page
> asking to accept the license terms before it downloads the package.
> How do
> I handle this using Ansible?

Since you need to answer the HTML form you can't use get_url since it
doesn't support sending that data, but the uri module does.
You can try this.

- uri:
url: https://www.segger.com/downloads/jlink/JLink_Linux_x86_64.deb
method: POST
body-format: form-urlencoded
body: accept_license_agreement=accepted
dest: /tmp/JLink_Linux_x86_64.deb

--
Kai Stian Olstad

Brian Peavey

unread,
Jul 19, 2018, 2:07:15 PM7/19/18
to Ansible Project
Thank you for the suggestion.  I tried this -

  - block:
    - name: Download SEGGER J-Link
#      get_url:
      uri:
        method: POST
        body_format: form-urlencoded
        body: accept_license_agreement=accepted
        dest: "{{download_dir}}/JLink_Linux_{{jlink_ver}}.deb"
#        checksum: "{{jlink_chk}}"
    - name: Install SEGGER J-Link
      become: true
      apt: 
        deb: "{{download_dir}}/JLink_Linux_{{jlink_ver}}.deb"
        state: present
    rescue:
      - debug:
          msg: "SEGGER J-Link Task Failed"

  but now I get this output - 

TASK [Download SEGGER J-Link] **************************************************
fatal: [simplexity-dev]: FAILED! => {"changed": false, "msg": "value of body_format must be one of: raw, json, got: form-urlencoded"}

TASK [debug] *******************************************************************
ok: [simplexity-dev] => {
    "msg": "SEGGER J-Link Task Failed"
}

  Not sure why it doesn't like the body_format.  I'm running ansible v2.5.5.
  Thanks...
Brian

Kai Stian Olstad

unread,
Jul 19, 2018, 2:32:11 PM7/19/18
to ansible...@googlegroups.com
On 19.07.2018 20:07, Brian Peavey wrote:
> Thank you for the suggestion. I tried this -
>
> - block:
> - name: Download SEGGER J-Link
> # get_url:
> uri:
> url:
> "https://www.segger.com/downloads/jlink/JLink_Linux_x86_64.deb"
> method: POST
> body_format: form-urlencoded
> body: accept_license_agreement=accepted
> dest: "{{download_dir}}/JLink_Linux_{{jlink_ver}}.deb"
> # checksum: "{{jlink_chk}}"

<snip />

> TASK [Download SEGGER J-Link]
> **************************************************
> fatal: [simplexity-dev]: FAILED! => {"changed": false, "msg": "value of
> body_format must be one of: raw, json, got: form-urlencoded"}
>
> TASK [debug]
> *******************************************************************
> ok: [simplexity-dev] => {
> "msg": "SEGGER J-Link Task Failed"
> }
>
> Not sure why it doesn't like the body_format. I'm running ansible
> v2.5.5.
> Thanks...

New syntax feature in 2.6, for 2.5 I think this should work

- name: Download SEGGER J-Link
body: accept_license_agreement=accepted
headers:
Content-Type: application/x-www-form-urlencoded
dest: "{{download_dir}}/JLink_Linux_{{jlink_ver}}.deb"

--
Kai Stian Olstad

Brian Peavey

unread,
Jul 19, 2018, 4:21:15 PM7/19/18
to Ansible Project
Thanks for the help - that worked great!

Brian
 
Reply all
Reply to author
Forward
0 new messages