首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法解析kubectl修补程序命令

无法解析kubectl修补程序命令
EN

Stack Overflow用户
提问于 2021-10-01 14:21:41
回答 1查看 156关注 0票数 1

我试图使用ansible在kubectl修补程序命令下面执行,但这会产生“我们无法以JSON或YAML的形式读取”错误。

我还试着在单引号和双引号之前添加转义字符,但没有运气。

我的任务是:

代码语言:javascript
复制
- name: Patching cnx-ingress to use loadbalancer provate ip as ingress. 

  shell: kubectl patch svc cnx-ingress-ingress-nginx-controller -n connections -p '{"spec": {"type": "LoadBalancer", "externalIPs":["172.26.0.13"]}}'   
  become_user: "{{ __sudo_user }}"

错误:

代码语言:javascript
复制
TASK [component-pack : Setup Community Ingress Controller] ********************************************************************************
fatal: [master1.internal.dev.net]: FAILED! => {"reason": "We were unable to read either as JSON nor YAML, these are the errors we got from each:\nJSON: No JSON object could be decoded\n\nSyntax Error while loading YAML.
\n  mapping values are not allowed here\n\nThe error appears to be in '/Users/ujjawalkhare/connections3/deployment-ansible/ansible/roles/hcl/component/tasks/setup_community_ingress.yml': line 207, column 111, but may\nbe elsewhere in the file depending on the exact syntax problem.
\n\nThe offending line appears to be:\n\n- 
name:                      Patching cnx-ingress to use loadbalancer provate ip as ingress\n  
shell:                     kubectl patch svc cnx-ingress-ingress-nginx-controller -n connections -p '{\"spec\": {\"type\": \"LoadBalancer\", \"externalIPs\":[\"172.26.0.13\"]}}'\n 
                                                                                                     ^ here\nWe could be wrong, but this one looks like it might be an issue with\nunbalanced quotes. If starting a value with a quote, make sure the\nline ends with the same set of quotes. For instance this arbitrary\nexample:\n\n    foo: \"bad\" \"wolf\"\n\nCould be written as:\n\n    foo: '\"bad\" \"wolf\"'\n"}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-01 14:26:29

您需要将整个参数引用到shell (因为它包含的字符使YAML解析器认为您正在尝试启动映射值)。因为您已经在脚本中同时使用单引号和双引号,所以您最好的选择是使用YAML的一个块引号操作符。也许:

代码语言:javascript
复制
    - name: Patching cnx-ingress to use loadbalancer provate ip as ingress.
      shell: >
        kubectl patch svc cnx-ingress-ingress-nginx-controller
        -n connections
        -p '{"spec": {"type": "LoadBalancer", "externalIPs":["172.26.0.13"]}}'
      become_user: "{{ __sudo_user }}"

另外,考虑使用Ansible k8s模块而不是运行kubectl patch

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69407468

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档