首页 > 解决方案 > 使用命令/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}

标签: ansible

解决方案


我安装了错误的 PYPI 包。巧合的是,有一个名为systemd(版本 0.16.1)的包,它与官方systemd-python(版本 234)包不同。运行pip3 uninstall systemd然后pip3 install systemd-python --user解决问题。


推荐阅读