我的k8s.yaml库存文件是:
plugin: k8s
connections:
- kubeconfig: '/Users/user1/Documents/Learning/ansible/kubeconfig.test.yaml'
context: '[email protected]'
ansible剧本:test_new.yml
- hosts: localhost
tasks:
- name: Create a k8s namespace
k8s:
name: testing3
api_version: v1
kind: Namespace
state: present
看起来ansibleplaybook命令没有拿起 list k8s.yaml。而且我不确定为什么我在组名警告中收到警告无效字符{'-'。请让我知道上面的 list 文件和ansible剧本文件看起来不错还是缺少什么?
ansible-playbook -vvvv -i k8s.yaml -vvv ./test_new.yml
No config file found; using defaults
setting up inventory plugins
host_list declined parsing /Users/user1/Documents/Learning/ansible/k8s.yaml as it did not pass its verify_file() method
script declined parsing /Users/user1/Documents/Learning/ansible/k8s.yaml as it did not pass its verify_file() method
Not replacing invalid character(s) "{'-', '9'}" in group name (909676E2B4F81625BF5994625D3353C9-yl4-us-east-1-eks-amazonaws-com)
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
Not replacing invalid character(s) "{'-'}" in group name (namespace_add-ons)
Not replacing invalid character(s) "{'-'}" in group name (namespace_add-ons_pods)
Not replacing invalid character(s) "{'.', '/', '-'}" in group name (label_app.kubernetes.io/instance_aws-cluster-autoscaler)
最佳答案
我不确定您从何处获得 list 文件中指定的Kubernetes参数。如果查看k8s module documentation,它说kubeconfig
和context
在剧本中指定或作为环境变量指定。
您的inventory应该看起来像这样:
all:
hosts:
host.where.can.access.the.kubeapiserver.com:
然后是您的剧本:- name: Create a k8s namespace
k8s:
name: testing3
api_version: v1
kind: Namespace
state: present
kubeconfig: '/Users/user1/Documents/Learning/ansible/kubeconfig.test.yaml' 👈 this can replaced by the K8S_AUTH_KUBECONFIG env variable
context: '[email protected]' 👈 this can replaced by the K8S_AUTH_CONTEXT env variable
关于kubernetes - 在群组名称中发现无效字符,但未替换可替换的k8s,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/62881518/