ansible - 使用 k8s 事实或 K8s 信息模块的 ansible 错误
问题描述
团队,
我正在尝试使用 k8s_facts 模块中的标签拉节点,但收到此错误。任何提示?
任务/main.yaml
#Pull all cpu nodes by class label then check if that node has nodeType label
- name: "Fetch all CPU nodes from clusters using K8s beta.kubernetes.io/instance-type"
k8s_facts:
kind: Node
label_selectors:
- "beta.kubernetes.io/instance-type={{ kube_cpu_node_class }}"
verify_ssl: no
register: cpu_class_list
failed_when: cpu_class_list == ''
输出:
16:00:16 ok: [localhost] => {
16:00:16 "changed": false,
16:00:16 "failed_when_result": false,
16:00:16 "module_stderr": "Traceback (most recent call last):\n File \"<stdin>\", line 114, in <module>\n File \"<stdin>\", line 106, in _ansiballz_main\n File \"<stdin>\", line 49, in invoke_module\n File \"/tmp/ansible_k8s_facts_payload_9r6jpU/__main__.py\", line 176, in <module>\n File \"/tmp/ansible_k8s_facts_payload_9r6jpU/__main__.py\", line 172, in main\n File \"/tmp/ansible_k8s_facts_payload_9r6jpU/__main__.py\", line 145, in execute_module\n File \"/tmp/ansible_k8s_facts_payload_9r6jpU/ansible_k8s_facts_payload.zip/ansible/module_utils/k8s/common.py\", line 186, in get_api_client\n File \"/usr/local/lib/python2.7/dist-packages/kubernetes/config/kube_config.py\", line 645, in load_kube_config\n persist_config=persist_config)\n File \"/usr/local/lib/python2.7/dist-packages/kubernetes/config/kube_config.py\", line 613, in _get_kube_config_loader_for_yaml_file\n **kwargs)\n File \"/usr/local/lib/python2.7/dist-packages/kubernetes/config/kube_config.py\", line 153, in __init__\n self.set_active_context(active_context)\n File \"/usr/local/lib/python2.7/dist-packages/kubernetes/config/kube_config.py\", line 173, in set_active_context\n context_name = self._config['current-context']\n File \"/usr/local/lib/python2.7/dist-packages/kubernetes/config/kube_config.py\", line 495, in __getitem__\n v = self.safe_get(key)\n File \"/usr/local/lib/python2.7/dist-packages/kubernetes/config/kube_config.py\", line 491, in safe_get\n key in self.value):\nTypeError: argument of type 'NoneType' is not iterable\n",
16:00:16 "module_stdout": "",
16:00:16 "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
16:00:16 "rc": 1
16:00:16 }
我已手动验证我的直接 kubectl 命令是否有效。所以它肯定是模块的一些设置问题?
当我切换到 k8s_info 模块时,出现语法错误。
- name: "Fetch all CPU nodes from clusters using K8s beta.kubernetes.io/instance-type"
k8s_info:
kind: Node
label_selectors:
- "beta.kubernetes.io/instance-type={{ kube_cpu_node_class }}"
verify_ssl: no
register: cpu_class_list
failed_when: cpu_class_list == ''
输出
16:14:22 ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.
16:14:22
16:14:22 The error appears to be in '/home/svcngcc/jenkins/workspace/nvdc/run_ansible_playbook/k8s/baremetal/roles/maglev-services-pre-install-checks/tasks/main.yml': line 72, column 9, but may
16:14:22 be elsewhere in the file depending on the exact syntax problem.
16:14:22
16:14:22 The offending line appears to be:
16:14:22
16:14:22 #Pull all cpu nodes by class label then check if that node has nodeType label
16:14:22 - name: "Fetch all CPU nodes from clusters using K8s beta.kubernetes.io/instance-type"
16:14:22 ^ here
解决方案
我必须通过 ansible 容器内的 pip 安装 kubernetes 并且它有效。
pip install openshift pip install kubernetes
推荐阅读
- r - glmnet 包中的问题
- node.js - 使用 populate() 的路由在生产中不起作用,但在本地运行良好
- html - HTML 输入错误消息在 iOS 上看起来很难看。如何造型?
- r - 用户编辑一个表,更改反映在另一个表中
- php - 用户无法验证 Laravel
- spring - 如何在 Spring Boot 中懒加载 Kafka Consumer?
- json - 在 Spring Boot RestAPI 响应中排除空的 Hateoas“链接”
- swift - 无法快速显示第一个视图控制器将值传递给第二个视图控制器
- microsoft-graph-api - com.microsoft.graph.http.GraphServiceException:错误代码:SyncStateInvalid
- amazon-s3 - 使用 AWS Amplify 在哪里以及如何获取“identityId”?