ansible - 无法将库存脚本解析为库存
问题描述
我的 python 脚本动态查询并生成一个 JSON 文件,如下所示:
{
"all": {
"hosts": [
"192.158.1.1"
],
"vars": {
"ansible_become_method": "sudo",
"ansible_become": "yes"
}
}
}
但是当我执行下面的命令时
ansible -i script.py -m ping
它发出以下警告信息
- [警告] 无法将 /etc/ansible/script.py 解析为清单源
- [警告] 没有解析清单,只有隐式本地主机可用。
- [警告] 提供的主机列表为空,只有 localhost 可用。请注意,隐式本地主机不匹配“全部”
我不知道我缺少什么或错了,因为我是 Ansible 动态库存的新手。
当我运行时,ansible-inventory -i script.py --list
我得到以下响应
{
"_meta": {
"hostvars": {}
},
"all": {
"children": [
"ungrouped"
]
},
"ungrouped": {}
}
我的 Ansible 版本是 2.7.7
库存插件是脚本
enable_plugins = script
[更新]根据史蒂夫的建议运行 -v 给了我更多
[WARNING]: * Failed to parse /etc/ansible/newhost.py with script plugin: failed to parse executable inventory script results from /etc/ansible/script.py: Syntax
Error while loading YAML. mapping values are not allowed in this context The error appears to have been in '<string>': line 3, column 8, but may be elsewhere in the
file depending on the exact syntax problem.
File "/usr/lib/python2.7/site-packages/ansible/plugins/inventory/script.py", line 125, in parse
raise AnsibleError("failed to parse executable inventory script results from {0}: {1}\n{2}".format(path, to_native(e), err))
解决方案
您是否在 python 清单脚本的第一行添加了这样的标题?
#!/path/to/python
推荐阅读
- macros - 在 Common Lisp 中定义一个定义一组函数和函数调用的宏
- java - 返回由字符串的奇数索引号组成的字符串
- python - django模板比较文件中的数据执行错误的代码路径
- javascript - setTimeout on if else 语句
- python - numpy数组中每个元素之间的差异
- python - 我正在尝试在 VSC python 中创建/激活虚拟环境
- c++ - 如何在派生类中实现虚函数?
- reactjs - 如何防止 flask_login 中的 current_user 被重置?
- ios - 简单的骰子应用程序 - 按时间顺序而不是随机顺序(Xcode - Swift)
- python - 有没有办法通过 Python xlwings 使用 Excel 工作表功能区中的命令/功能?