Reliably getting user homedir, despite become

I’d like these results when querying a remote machine, but am having problems finding the correct user vars to pass

‘sometypeofuser’: Alice,
become: true
Result: /home/alice

‘sometypeofuser’: Alice,
become: false
Result: /home/alice

‘sometypeofuser’: root
become: true or false
Result: /root/

Got myself in a muddle here so an example would be much appreciated please,
It’s also possible that I’ve made a mistake in my inventory that I can’t find at the moment.

I’ve been trying

command: echo ~
This isn’t ideal as is affected by become and also registers a ‘changed’ in the results

ansible_env.HOME but am always getting the account running the play

Also, I may be mistaken here but seems that if you run the play on the control machine is doesn’t ssh out and then in and that changes the ansible.env results (?)

Thank you in advance

ansilbe_env reflects 'the user used to gather facts on that target',
if the target is localhost .. that is what you get.

As for getting the home of the of user that logged in, the following
should work for most common cases:

shell: getent passwd ${SUDO_USER:-$LOGNAME}|cut -f 6 -d ":"