Simon Simon - 3 months ago 23
HTTP Question

Ansible: Install tarball via HTTP

I'd like to extend my ansible playbook to install/verify installation of phantomjs and wkhtmltopdf to my Debian 7 machine. Both programs are available as packed tarballs via HTTP. I know the get_url module, but it doesn't unpack stuff, and if I'd add some shell commands for unpacking and moving the binaries, I suspect each time I run ansible, the tarballs would be downloaded, unpacked and moved again, causing unnecessary network traffic.

How can I solve this? Should I make a .deb file and run that using the apt command, or should I make a new ansible module for installing tarballs, or is there something that I'm overlooking?

Answer

If you download specific versions (e.g. foo_1.2.3.tar.gz and not foo_latest.tar.gz), you can do this by keeping the downloaded tarball :

- name: Gets tarball
  sudo: yes
  sudo_user: "{{ deploy_user }}"
  get_url:
    url="http://some.host/some_tarball-{{ tarball_version }}.tar.gz"
    dest="/home/{{ deploy_user }}/"
  register: new_archive

- name: Unarchive source
  sudo: yes
  sudo_user: "{{ deploy_user }}"
  unarchive:
    src="/home/{{ deploy_user }}/some_tarball-{{ tarball_version }}.tar.gz"
    dest="/home/{{ deploy_user }}/app/"
    copy=no
  when: new_archive|changed

Change variables according to your environment.