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