This works fine, but I don’t want the user name to be hardcoded. Here and here there are examples that remote_user can be passed via {{ ansible_ssh_user }} but I can’t get it to work.
Yes it works if I set ansible_ssh_user as variable in the inventory file, but for my purpose it’s the same as hardcoding it. What I want to do is to share this with my colleagues, so they can also use it without making any changes.
You can use this global variable in the playbook. As an example:
name: Playbook to test default user
hosts: all
gather_facts: false
tasks:
It 'works' in certain cases and debug is a bad example of that, once
the PR I linked is merged we will probably deprecate any updates to
ansible_* vars as they are currently inconsistent and many times wrong
(especially when you consider loops).