Ansible win_updates 无法在 Debian 11 上运行 /("msg": "winrm put_file failed;\nstdout: Active code page: 1252\r)
Ansible win_updates won't work on Debian 11 /("msg": "winrm put_file failed; \nstdout: Active code page: 1252\r)
我是 Ansible 的新手,现在已经开始自动化一些重复的 Windows 管理任务。
作为控制器,我使用 Debian 11 VM,其中我只安装了 Ansible 和 pywinrm。
我的测试目标是 Windows Server 2016,一切正常,我可以安装程序、创建用户或复制文件。唯一不起作用的是模块“win_updates”。
我打电话给 win_updates 时收到以下消息。
fatal: [ws2016-test01.minimaximal.de]: FAILED! => {"changed": false, "failed_update_count": 0, "filtered_updates": {}, "found_update_count": 0, "installed_up date_count": 0, "msg": "winrm put_file failed; \nstdout: Active code page: 1252\r\n{\"sha1\":\"753fdd143ad8962c56d33e56b128f3d4d19cfd3b\"}\r\n\nstderr ", "up dates": {}}
与 -vvv
Traceback (most recent call last):
File "/home/testuser/.local/lib/python3.9/site-packages/ansible/plugins/connection/winrm.py", line 661, in put_file
put_output = json.loads(result.std_out)
File "/usr/lib/python3.9/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.9/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.9/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/testuser/.ansible/collections/ansible_collections/ansible/windows/plugins/action/win_updates.py", line 761, in run
result = self._run_sync(task_vars, module_options, reboot, reboot_timeout)
File "/home/testuser/.ansible/collections/ansible_collections/ansible/windows/plugins/action/win_updates.py", line 821, in _run_sync
poll_script_path = self._copy_script(_POLL_SCRIPT, 'poll.ps1')
File "/home/testuser/.ansible/collections/ansible_collections/ansible/windows/plugins/action/win_updates.py", line 1036, in _copy_script
self._transfer_file(to_text(b_local_script, errors='surrogate_or_strict'), remote_path)
File "/home/testuser/.local/lib/python3.9/site-packages/ansible/plugins/action/__init__.py", line 477, in _transfer_file
self._connection.put_file(local_path, remote_path)
File "/home/testuser/.local/lib/python3.9/site-packages/ansible/plugins/connection/winrm.py", line 667, in put_file
raise AnsibleError('winrm put_file failed; \nstdout: %s\nstderr %s' % (to_native(result.std_out), to_native(stderr)))
ansible.errors.AnsibleError: winrm put_file failed;
stdout: Active code page: 1252
{"sha1":"753fdd143ad8962c56d33e56b128f3d4d19cfd3b"}
stderr
fatal: [ws2016-test01.minimaximal.de]: FAILED! => {
"changed": false,
"failed_update_count": 0,
"filtered_updates": {},
"found_update_count": 0,
"installed_update_count": 0,
"msg": "winrm put_file failed; \nstdout: Active code page: 1252\r\n{\"sha1\":\"753fdd143ad8962c56d33e56b128f3d4d19cfd3b\"}\r\n\nstderr ",
"updates": {}
}
我已经在 CentOS 8 机器上针对同一目标 Windows 服务器测试了完全相同的剧本,没有任何问题。
我测试了不同的 Ansible 和 Python 版本,Debian 控制器上的版本与工作的 CentOS 机器上的版本相同,没有区别。
我很确定这不是 Windows 问题,也不是 Ansible 问题。
我个人认为这与 Python 依赖项丢失或损坏有关。
ansible --version
config file = None
configured module search path = ['/home/testuser/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/testuser/.local/lib/python3.9/site-packages/ansible
ansible collection location = /home/testuser/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
jinja version = 3.0.3
libyaml = True
pip3 列表
Package Version
----------------- --------------
ansible 5.2.0
ansible-base 2.10.8
ansible-core 2.12.1
apache-libcloud 3.2.0
argcomplete 1.8.1
certifi 2020.6.20
cffi 1.15.0
chardet 4.0.0
cryptography 36.0.1
dnspython 2.0.0
httplib2 0.18.1
idna 2.10
Jinja2 3.0.3
jmespath 0.10.0
lockfile 0.12.2
MarkupSafe 2.0.1
netaddr 0.7.19
ntlm-auth 1.5.0
packaging 21.3
pip 20.3.4
pycparser 2.21
pycryptodomex 3.9.7
pycurl 7.43.0.6
pykerberos 1.1.14
pyparsing 3.0.6
PySimpleSOAP 1.16.2
python-apt 2.2.1
python-debian 0.1.39
python-debianbts 3.1.0
pywinrm 0.4.2
PyYAML 6.0
reportbug 7.10.3+deb11u1
requests 2.25.1
requests-kerberos 0.12.0
requests-ntlm 1.1.0
requests-toolbelt 0.9.1
resolvelib 0.5.4
selinux 3.1
setuptools 52.0.0
simplejson 3.17.2
six 1.16.0
urllib3 1.26.5
wheel 0.34.2
xmltodict 0.12.0
我的失败测试手册
- name: "win_updates"
hosts: all
tasks:
- name: install important updates
ansible.windows.win_updates:
category_names:
- SecurityUpdates
- CriticalUpdates
试了1.5天没有成功,我真的很迷茫,除了换CentOS,别的什么都不知道了,但是我们的其他系统都是Debian。
任何想法可能是什么问题?
添加合适的环境变量解决了我的问题。
env LANG=C LC_ALL=C ansible-playbook ...
我还创建了一个新的 Debian VM 并在其上安装了 Ansible,它开箱即用。可能我在第一次安装 Ansible 时破坏了一些东西。
我是 Ansible 的新手,现在已经开始自动化一些重复的 Windows 管理任务。
作为控制器,我使用 Debian 11 VM,其中我只安装了 Ansible 和 pywinrm。 我的测试目标是 Windows Server 2016,一切正常,我可以安装程序、创建用户或复制文件。唯一不起作用的是模块“win_updates”。
我打电话给 win_updates 时收到以下消息。
fatal: [ws2016-test01.minimaximal.de]: FAILED! => {"changed": false, "failed_update_count": 0, "filtered_updates": {}, "found_update_count": 0, "installed_up date_count": 0, "msg": "winrm put_file failed; \nstdout: Active code page: 1252\r\n{\"sha1\":\"753fdd143ad8962c56d33e56b128f3d4d19cfd3b\"}\r\n\nstderr ", "up dates": {}}
与 -vvv
Traceback (most recent call last):
File "/home/testuser/.local/lib/python3.9/site-packages/ansible/plugins/connection/winrm.py", line 661, in put_file
put_output = json.loads(result.std_out)
File "/usr/lib/python3.9/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.9/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.9/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/testuser/.ansible/collections/ansible_collections/ansible/windows/plugins/action/win_updates.py", line 761, in run
result = self._run_sync(task_vars, module_options, reboot, reboot_timeout)
File "/home/testuser/.ansible/collections/ansible_collections/ansible/windows/plugins/action/win_updates.py", line 821, in _run_sync
poll_script_path = self._copy_script(_POLL_SCRIPT, 'poll.ps1')
File "/home/testuser/.ansible/collections/ansible_collections/ansible/windows/plugins/action/win_updates.py", line 1036, in _copy_script
self._transfer_file(to_text(b_local_script, errors='surrogate_or_strict'), remote_path)
File "/home/testuser/.local/lib/python3.9/site-packages/ansible/plugins/action/__init__.py", line 477, in _transfer_file
self._connection.put_file(local_path, remote_path)
File "/home/testuser/.local/lib/python3.9/site-packages/ansible/plugins/connection/winrm.py", line 667, in put_file
raise AnsibleError('winrm put_file failed; \nstdout: %s\nstderr %s' % (to_native(result.std_out), to_native(stderr)))
ansible.errors.AnsibleError: winrm put_file failed;
stdout: Active code page: 1252
{"sha1":"753fdd143ad8962c56d33e56b128f3d4d19cfd3b"}
stderr
fatal: [ws2016-test01.minimaximal.de]: FAILED! => {
"changed": false,
"failed_update_count": 0,
"filtered_updates": {},
"found_update_count": 0,
"installed_update_count": 0,
"msg": "winrm put_file failed; \nstdout: Active code page: 1252\r\n{\"sha1\":\"753fdd143ad8962c56d33e56b128f3d4d19cfd3b\"}\r\n\nstderr ",
"updates": {}
}
我已经在 CentOS 8 机器上针对同一目标 Windows 服务器测试了完全相同的剧本,没有任何问题。 我测试了不同的 Ansible 和 Python 版本,Debian 控制器上的版本与工作的 CentOS 机器上的版本相同,没有区别。
我很确定这不是 Windows 问题,也不是 Ansible 问题。 我个人认为这与 Python 依赖项丢失或损坏有关。
ansible --version
config file = None
configured module search path = ['/home/testuser/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/testuser/.local/lib/python3.9/site-packages/ansible
ansible collection location = /home/testuser/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
jinja version = 3.0.3
libyaml = True
pip3 列表
Package Version
----------------- --------------
ansible 5.2.0
ansible-base 2.10.8
ansible-core 2.12.1
apache-libcloud 3.2.0
argcomplete 1.8.1
certifi 2020.6.20
cffi 1.15.0
chardet 4.0.0
cryptography 36.0.1
dnspython 2.0.0
httplib2 0.18.1
idna 2.10
Jinja2 3.0.3
jmespath 0.10.0
lockfile 0.12.2
MarkupSafe 2.0.1
netaddr 0.7.19
ntlm-auth 1.5.0
packaging 21.3
pip 20.3.4
pycparser 2.21
pycryptodomex 3.9.7
pycurl 7.43.0.6
pykerberos 1.1.14
pyparsing 3.0.6
PySimpleSOAP 1.16.2
python-apt 2.2.1
python-debian 0.1.39
python-debianbts 3.1.0
pywinrm 0.4.2
PyYAML 6.0
reportbug 7.10.3+deb11u1
requests 2.25.1
requests-kerberos 0.12.0
requests-ntlm 1.1.0
requests-toolbelt 0.9.1
resolvelib 0.5.4
selinux 3.1
setuptools 52.0.0
simplejson 3.17.2
six 1.16.0
urllib3 1.26.5
wheel 0.34.2
xmltodict 0.12.0
我的失败测试手册
- name: "win_updates"
hosts: all
tasks:
- name: install important updates
ansible.windows.win_updates:
category_names:
- SecurityUpdates
- CriticalUpdates
试了1.5天没有成功,我真的很迷茫,除了换CentOS,别的什么都不知道了,但是我们的其他系统都是Debian。
任何想法可能是什么问题?
添加合适的环境变量解决了我的问题。
env LANG=C LC_ALL=C ansible-playbook ...
我还创建了一个新的 Debian VM 并在其上安装了 Ansible,它开箱即用。可能我在第一次安装 Ansible 时破坏了一些东西。