My colleagues told me to not use ~ when I write paths, so I use instead the environment variable $HOME.
I have one task which works fine:
ansible.builtin.lineinfile:
  path: $HOME/.ssh/known_hosts
  [...]
On the other hand, this one fails:
community.windows.win_lineinfile:
  line: "{{ lookup('file', '$HOME/.ssh/id_ed25519.pub') }}"
  [...]
Is it not possible to use environment variables inside a lookup?
My current solution is:
line: "{{ lookup('file', lookup('env', 'HOME')+'/.ssh/id_ed25519.pub') }}"
but it is ugly.
 
     
    