[英]ansible dynamic inventory kubernetes
I am trying to use the kubernetes plugin in ansible to be able to use a dynamic inventory based on my k8 cluster.我正在尝试在 ansible 中使用 kubernetes 插件,以便能够使用基于我的 k8 集群的动态清单。 I have followed this doc https://docs.ansible.com/ansible/latest/scenario_guides/kubernetes_scenarios/k8s_inventory.html however i keep getting a failed to parse error.
我已经关注了这个文档https://docs.ansible.com/ansible/latest/scenario_guides/kubernetes_scenarios/k8s_inventory.html但是我一直遇到解析失败的错误。
# ansible-inventory --list -i k8s.yaml
[WARNING]: * Failed to parse /etc/ansible/k8s.yaml with ansible_collections.kubernetes.core.plugins.inventory.k8s plugin: Invalid value "kubernetes.core.k8s" for configuration option "plugin_type: inventory
plugin: ansible_collections.kubernetes.core.plugins.inventory.k8s setting: plugin ", valid values are: ['k8s']
[WARNING]: Unable to parse /etc/ansible/k8s.yaml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
{
"_meta": {
"hostvars": {}
},
"all": {
"children": [
"ungrouped"
]
}
}
extract from ansible.cfg从 ansible.cfg 中提取
# egrep -i "\[inventory\]|kubernetes" ansible.cfg
[inventory]
enable_plugins = kubernetes.core.k8s
k8s.yaml k8s.yaml
# cat k8s.yaml
plugin: kubernetes.core.k8s
The error suggests that kubernetes.core.k8s
is an invalid value and that valid values are ['k8s']
.该错误表明
kubernetes.core.k8s
是无效值,有效值为['k8s']
。 yet this is exactly whats in the documentation, I have tried all manor of altering the plugin name with no success.但这正是文档中的内容,我尝试了所有更改插件名称的方法,但均未成功。
Can anyone steer me on what i am missing here?任何人都可以引导我了解我在这里缺少的东西吗?
So I managed to get it working by editing /usr/lib/python3/dist-packages/ansible_collections/kubernetes/core/plugins/inventory/k8s.py
it seems my version only listed k8s
as a pluggin name, I replaced with, kubernetes.core.k8s
and it worked所以我设法通过编辑
/usr/lib/python3/dist-packages/ansible_collections/kubernetes/core/plugins/inventory/k8s.py
让它工作,看来我的版本只将k8s
列为k8s
名称,我替换为kubernetes.core.k8s
并且有效
options:
plugin:
description: token that ensures this is a source file for the 'k8s' plugin.
required: True
choices: ['kubernetes.core.k8s']
I did plan to raise it as a PR on the project but seems this was already updated several months back so I must have just had outdated files.我确实计划将它作为项目的 PR 提出,但似乎这已经在几个月前更新了,所以我一定只是有过时的文件。
https://github.com/ansible-collections/kubernetes.core/blob/60933457e81fcfa1000f556b2bc3425bbf080602/plugins/inventory/k8s.py#L27 https://github.com/ansible-collections/kubernetes.core/blob/60933457e81fcfa1000f556b2bc3425bbf080602/plugins/inventory/k8s.py#L27
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.