亂碼緣由是由於 Linux 和 Windows 編碼不一致所致使python
修改環境變量便可shell
設置環境變量爲 utf-8bash
ansible win_test -m win_shell -a 'Set-Item -Path env:PYTHONIOENCODING -Value "utf-8"; python d:\test\stat.py' # playbook --- - hosts: win_test gather_facts: no tasks: - name: run Python script with utf-8 output win_command: Python.exe d:\test\stat.py environment: PYTHONIOENCODING: utf-8