ansible - 使用命令/shell 模块会导致:ValueError:键名在多次运行时可能不以下划线开头
问题描述
Ansible 在每个使用 shell 或命令模块的任务上都会抛出错误,但在新机器上第一次运行时不会。
我使用的过程是镜像一个新的树莓派,然后使用 ansible 设置我需要的服务。第一次运行 ansible 工作正常,但如果我再次运行它(不改变任何东西)它会失败,说ValueError: Key name may not begin with an underscore
下面是一个引发错误的任务示例。在远程机器上运行/usr/local/bin/pigpiod -v
按预期工作/
- name: see if pigpiod is the correct version
command: "/usr/local/bin/pigpiod -v"
register: pigpiod_version
这是错误:
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ValueError: Key name may not begin with an underscore
fatal: [issacs_box]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n File \"<stdin>\", line 113, in <module>\n File \"<stdin>\", line 105, in _ansiballz_main\n File \"<stdin>\", line 48, in invoke_module\n File \"/usr/lib/python3.5/imp.py\", line 234, in load_module\n return load_source(name, filename, file)\n File \"/usr/lib/python3.5/imp.py\", line 170, in load_source\n module = _exec(spec, sys.modules[name])\n File \"<frozen importlib._bootstrap>\", line 626, in _exec\n File \"<frozen importlib._bootstrap_external>\", line 673, in exec_module\n File \"<frozen importlib._bootstrap>\", line 222, in _call_with_frames_removed\n File \"/tmp/ansible_command_payload_hc3z4iej/__main__.py\", line 292, in <module>\n File \"/tmp/ansible_command_payload_hc3z4iej/__main__.py\", line 199, in main\n File \"/tmp/ansible_command_payload_hc3z4iej/ansible_command_payload.zip/ansible/module_utils/basic.py\", line 901, in __init__\n File \"/tmp/ansible_command_payload_hc3z4iej/ansible_command_payload.zip/ansible/module_utils/basic.py\", line 2243, in _log_invocation\n File \"/tmp/ansible_command_payload_hc3z4iej/ansible_command_payload.zip/ansible/module_utils/basic.py\", line 2201, in log\n File \"systemd/_journal.pyx\", line 68, in systemd._journal.send\n File \"systemd/_journal.pyx\", line 32, in systemd._journal._send\nValueError: Key name may not begin with an underscore\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
解决方案
我安装了错误的 PYPI 包。巧合的是,有一个名为systemd
(版本 0.16.1)的包,它与官方systemd-python
(版本 234)包不同。运行pip3 uninstall systemd
然后pip3 install systemd-python --user
解决问题。
推荐阅读
- python - 安装任何东西时都会出错
- javascript - 从 localStorage 设置 Form.Check 默认值
- excel - 如何加入相关国家和城市的谷歌表格
- c# - 单击图像按钮时 Outlook VSTO 代码崩溃
- python - 在日期级别上减去日期时间对象
- python-3.x - 将 Django Rest Framework 的默认 url 更改为自定义
- python-3.x - 安装python任务要求时没有提供请求的任务2.8.0
- java - 如何从 xml 文件中读取 html 标签?
- xcode - 我可以在 Xcode 12.3 上调试 tvOS 14.6 吗?
- ios - PDFNet Resize annot Swift