Using tilde (~) in destination for unarchive module

Hey all,

I’m trying to unzip a file into a directory relative to the home directory on a host server. The problem is that when Ansible runs the unarchive module, it replaces the tilde in the variable with master server’s home directory instead of the host server’s. The file module correctly creates the directory on the host server. Here’s the playbook I’m using

  • hosts: myhost
    vars:
    mydir: “~/folder1/folder2/”
    user: myuser
    tasks:
  • name: Ensure the parent directory is present
    file: >
    path={{ mydir }}
    state=directory
  • name: Unzip the file into the host
    unarchive: >
    src=/ansible/archive/file.zip
    dest={{ mydir }}

Is there some argument I can give to unarchive so that it tries to unzip into the right directory? I’ve tried setting the HOME environment variable to the correct home directory on the host, but that does not make a difference.

Thanks,
Chip

from the unarchive docs:

  • copy
    if true, the file is copied from the ‘master’ to the target
    machine, otherwise, the plugin will look for src archive at
    the target machine. (Choices: yes, no) [Default: yes]

Thanks for the reply.

I am copying the zip file from the master server to the host, so I cannot set copy to ‘no’.

As a workaround, I could copy the zip file onto the host first, and then unarchive while setting copy to ‘no’, but I’d rather do it all in one step without copying the zip file to the ‘host’.

I’m sorry, I misunderstood, unarchive should never resolve on master the ‘dest’ unless it is also the target.

Do note, there were some places in the code that mistakenly expanded the tilde on the ansible controller side that were fixed recently. Are you using ansible 1.7.2 or are you using a checkout of development? If you can give us a minimal playbook to reproduce I could see if it has been fixed.

-Toshio

Toshio,

I am currently using 1.7.2

The text above should be enough of a playbook for you to reproduce the issue. Here it is again below. Just use any host, user and zip file you have to try it out. The issue occurs when unarchiving into the host “dest” directory which doesn’t exist because the tilde was evaluated as the home directory of the master server (for that reason, make sure the home directories of your master and host are not the same).

Hey Chip, I can confirm that the unarchive module is not handling the
tilde correctly in 1.7.2 and the bug is fixed in the devel branch.

The following two commits implemented the fix:

https://github.com/ansible/ansible/commit/bc4272d2a26e47418c7d588208482d05a34a34cd

https://github.com/ansible/ansible/commit/565e5bbdfc42afe29c4f53b303352d7e8406dcba

We're hoping to have 1.8 out very soon which should have the fix in it.

-Toshio