Using unarchive with local archives

17 Apr 2014

Ansible’s unarchive module has been around a while but it’s not always been suitable for use on archives local to the destination node (especially when running ansible-playbook on the destination host using the local connection. There are two key elements to this tip:

Use copy=no to ensure that no attempt is made to copy the archive from the host running ansible to the destination node

dest must end in a slash! This is because it uses pythons os.path.dirname to check if the directory is writable - if you have write access to say /usr/local, and use dest=/usr/local, it will actually check whether you have write access to /usr, and fail if you don't. So use dest=/usr/local/
- hosts: localhost
  connection: local

  tasks:
  - name: download artefact from website
    get_url: url="http://www.example.com/downloads/archive.tgz" dest="/tmp/archive.tgz"

  - name: extract artefact under /usr/local
    unarchive: copy=no src="/tmp/archive.tgz" dest="/usr/local/"