Your playbook works fine for me:
PLAY [all] ************
TASK [Gathering Facts] ***********************
ok: [trixie1]
TASK [Ensure the user is switched to oracle] *************************************************
changed: [trixie1] => {"changed": true, "cmd": ["whoami"], "delta": "0:00:00.006181", "end": "2025-04-25 07:38:05.349396", "msg": "", "rc": 0, "start": "2025-04-25 07:38:05.343215", "stderr": "", "stderr_lines": [], "stdout": "oracle", "stdout_lines": ["oracle"]}
TASK [Debug the output of whoami] ************************************************************
ok: [trixie1] => {
"msg": "The current user is: oracle"
}
PLAY RECAP ***********************************************************************************
trixie1 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Target OS: Debian Trixie (13)
However, I am unable to achieve the same result using the Ansible playbook.
Did you face any Ansible errors? Can you provide trace back?