Marek M
Marek M

Reputation: 11

Ansible - download a file from Google Drive

I'm creating a role in Ansible and got stuck on a step that requires downloading a publicly shared archive from Google Drive (https://drive.google.com/file/d/0BxpbZGYVZsEeSFdrUnBNMUp1YzQ/view?usp=sharing).

I didn't find any Ansible module that would be able to get such file from Gdrive and (as far as I know) it's not possible to get a direct link with extension at the end...

Is there any solution for this problem, or do I need to download it and upload somewhere else, so I could then get it directly through Ansible get_url module?

Upvotes: 0

Views: 3560

Answers (2)

vitro
vitro

Reputation: 939

You can do it like this:

    - name: Download archive from google drive
      get_url:
        url: "https://drive.google.com/uc?export=download&id={{ file_id }}"
        dest: /file/destination/file.tgz
        mode: u=r,g-r,o=r

For file_id use 0BxpbZGYVZsEeSFdrUnBNMUp1YzQ

Upvotes: 0

Marek M
Marek M

Reputation: 11

I found a solution myself :)

By using third-party script from here: https://github.com/circulosmeos/gdown.pl/blob/master/gdown.pl

And then running command module with proper arguments to download the file.


- name: Copy "gdown" script to /usr/local/bin
  copy: src=gdown.pl
        dest=/usr/local/bin/gdown
        mode=0755

- name: Download DRAGNN CONLL2017 data archive
  command: "/usr/local/bin/gdown {{ dragnn_data_url }} {{ dragnn_dir }}/conll17.tar.gz"
  args:
      creates: "{{ dragnn_dir }}/conll17.tar.gz"
  become_user: "{{ docker_user }}"
  become: yes
  become_method: sudo

Upvotes: 1

Related Questions