Quando executo o comando "quem sou eu" usando o módulo 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
Acho que o motivo é que o ansible não está usando um shell de login para executar o comando. Portanto, o comando não está exibindo nada.
Você deve ver uma saída.