# Using tilde (~) in destination for unarchive module

**URL:** <https://forum.ansible.com/t/using-tilde-in-destination-for-unarchive-module/16827>\
**Category:** Ansible Project\
**Created:** [November 19, 2014, 5:21pm UTC](https://forum.ansible.com/t/using-tilde-in-destination-for-unarchive-module/16827 "2014-11-19T17:21:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cselden](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/cselden/32/4405_2.png) [@cselden](https://forum.ansible.com/u/cselden)\
**Post date:** [November 19, 2014, 5:21pm UTC](https://forum.ansible.com/t/using-tilde-in-destination-for-unarchive-module/16827/1 "2014-11-19T17:21:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [November 19, 2014, 5:24pm UTC](https://forum.ansible.com/t/using-tilde-in-destination-for-unarchive-module/16827/2 "2014-11-19T17:24:44Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![cselden](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/cselden/32/4405_2.png) [@cselden](https://forum.ansible.com/u/cselden)\
**Post date:** [November 19, 2014, 5:33pm UTC](https://forum.ansible.com/t/using-tilde-in-destination-for-unarchive-module/16827/3 "2014-11-19T17:33:07Z")

</div>

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’.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [November 19, 2014, 6:20pm UTC](https://forum.ansible.com/t/using-tilde-in-destination-for-unarchive-module/16827/4 "2014-11-19T18:20:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Toshio\_Kuratomi](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Toshio\_Kuratomi](https://forum.ansible.com/u/Toshio_Kuratomi)\
**Post date:** [November 20, 2014, 3:28pm UTC](https://forum.ansible.com/t/using-tilde-in-destination-for-unarchive-module/16827/5 "2014-11-20T15:28:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cselden](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/cselden/32/4405_2.png) [@cselden](https://forum.ansible.com/u/cselden)\
**Post date:** [November 21, 2014, 1:07am UTC](https://forum.ansible.com/t/using-tilde-in-destination-for-unarchive-module/16827/6 "2014-11-21T01:07:08Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![Toshio\_Kuratomi](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Toshio\_Kuratomi](https://forum.ansible.com/u/Toshio_Kuratomi)\
**Post date:** [November 21, 2014, 3:47pm UTC](https://forum.ansible.com/t/using-tilde-in-destination-for-unarchive-module/16827/7 "2014-11-21T15:47:32Z")

</div>

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/bc4272d2a26e47418c7d588208482d05a34a34cd)

[https://github.com/ansible/ansible/commit/565e5bbdfc42afe29c4f53b303352d7e8406dcba](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
