{"action":"opened","issue":{"url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/1682","labels_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/1682/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/1682/comments","events_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/1682/events","html_url":"https://github.com/ansible/ansible-modules-core/issues/1682","id":93556256,"number":1682,"title":"Wrong home directory when setting HOME in template module","user":{"login":"Eronarn","id":536435,"avatar_url":"https://avatars.githubusercontent.com/u/536435?v=3","gravatar_id":"","url":"https://api.github.com/users/Eronarn","html_url":"https://github.com/Eronarn","followers_url":"https://api.github.com/users/Eronarn/followers","following_url":"https://api.github.com/users/Eronarn/following{/other_user}","gists_url":"https://api.github.com/users/Eronarn/gists{/gist_id}","starred_url":"https://api.github.com/users/Eronarn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Eronarn/subscriptions","organizations_url":"https://api.github.com/users/Eronarn/orgs","repos_url":"https://api.github.com/users/Eronarn/repos","events_url":"https://api.github.com/users/Eronarn/events{/privacy}","received_events_url":"https://api.github.com/users/Eronarn/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-07-07T15:20:24Z","updated_at":"2015-07-07T15:20:24Z","closed_at":null,"body":"All of the servers that I'm working with have HOME set to '/users/foobar', but not all of them have the '/users' NFS mount. This means that on some servers, my HOME will be a non-existent directory that I don't actually want created. In that case, I may want to temporarily set HOME to something else using 'environment' in Ansible, so that applications that assume you have a home directory can still function. However, this is what actually happens:\r\n\r\n```\r\n...\r\n<contecentral> EXEC /bin/sh -c 'echo ~'\r\n<contecentral> EXEC /bin/sh -c 'rc=flag; [ -r /users/jmeickle/.hgrc ] || rc=2; [ -f /users/jmeickle/.hgrc ] || rc=1; [ -d /users/jmeickle/.hgrc ] && rc=3; python -V 2>/dev/null || rc=4; [ x\"$rc\" != \"xflag\" ] && echo \"${rc} \"/users/jmeickle/.hgrc && exit 0; (python -c '\"'\"'import hashlib; BLOCKSIZE = 65536; hasher = hashlib.sha1(); afile = open(\"'\"'\"'/users/jmeickle/.hgrc'\"'\"'\", \"rb\") buf = afile.read(BLOCKSIZE) while len(buf) > 0: hasher.update(buf) buf = afile.read(BLOCKSIZE) afile.close() print(hasher.hexdigest())'\"'\"' 2>/dev/null) || (python -c '\"'\"'import sha; BLOCKSIZE = 65536; hasher = sha.sha(); afile = open(\"'\"'\"'/users/jmeickle/.hgrc'\"'\"'\", \"rb\") buf = afile.read(BLOCKSIZE) while len(buf) > 0: hasher.update(buf) buf = afile.read(BLOCKSIZE) afile.close() print(hasher.hexdigest())'\"'\"' 2>/dev/null) || (echo '\"'\"'0 '\"'\"'/users/jmeickle/.hgrc)'\r\n<contecentral> PUT /var/folders/ly/m06wlhmd2r3f62fdmyd758980000gn/T/tmpegx5_W TO /tmp/jmeickle/.ansible/ansible-tmp-1436281880.06-119983303138795/source\r\n<contecentral> PUT /var/folders/ly/m06wlhmd2r3f62fdmyd758980000gn/T/tmpsVXGU9 TO /tmp/jmeickle/.ansible/ansible-tmp-1436281880.06-119983303138795/copy\r\n<contecentral> EXEC /bin/sh -c 'LANG=en_US.UTF-8 HOME=/my/actual/value LC_CTYPE=en_US.UTF-8 /usr/bin/python /tmp/jmeickle/.ansible/ansible-tmp-1436281880.06-119983303138795/copy'\r\n```\r\n\r\nFrom what I can tell, it's generating the ansible 'copy' file that gets executed by echoing '~' to the remote host, without echoing the environment variables applied to the task, and thus not allowing an override of HOME properly. If it's going to ask the host to expand that value in advance, it should provide the same environment variables in case they would result in the value of '~' changing."}}