O motivo pelo qual eu penso é que ansible não está usando um shell de login para executar o comando. Então o comando não está exibindo nada.
If you replace:
who am i
with:
su - anotheruser; who am i
Você deve ver uma saída.
Quando executo o comando "who am i" usando o módulo de shell do ansible, recebo uma resposta vazia, não consigo descobrir por quê?
hosts: server1
remote_user: devops
become: true
tasks:
- name: print current user
shell: who am i
register: userr
- debug:
msg: "{{ userr.stdout }}"
[root@ansible test]# ansible-playbook test.yml
PLAY [test playbook] ********************************************************************************************************************************
TASK [Gathering Facts] ******************************************************************************************************************************
ok: [server1]
TASK [print current user] ***************************************************************************************************************************
changed: [server1]
TASK [debug] ****************************************************************************************************************************************
ok: [server1] => {
"msg": ""
}
PLAY RECAP ******************************************************************************************************************************************
server1 : ok=3 changed=1 unreachable=0 failed=0
Tags ansible