我试图使用ansible在kubectl修补程序命令下面执行,但这会产生“我们无法以JSON或YAML的形式读取”错误。
我还试着在单引号和双引号之前添加转义字符,但没有运气。
我的任务是:
- 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 }}"错误:
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"}发布于 2021-10-01 14:26:29
您需要将整个参数引用到shell (因为它包含的字符使YAML解析器认为您正在尝试启动映射值)。因为您已经在脚本中同时使用单引号和双引号,所以您最好的选择是使用YAML的一个块引号操作符。也许:
- 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。
https://stackoverflow.com/questions/69407468
复制相似问题