Thank you for your answer.
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:
- name: Print default users
debug:
var: ansible_user
When I run it with ansible-playbook test-default-user.yml --limit server1 I get
ok: [server1] => {
"ansible_user": "foo.bar"
}
Also works with ansible_ssh_user. So I thought it's the same with the inventory.