问题
要在line line命令中进行缩进,需要在命令的后续行处放置空格,以将其拆分为多行。
- name: "Update kubeconfig to set cluster"
shell: >
kubectl config set-cluster {{ item.cluster }}
--kubeconfig=~{{ item.account }}/.kube/config
--server={{ K8S_MASTER_HOSTNAME }}:{{ K8S_API_SERCURE_PORT }}
--embed-certs=true
--certificate-authority={{ K8S_CA_HOME }}/ca.crt
with_items: "{{ k8s_users }}"有什么办法可以做到这一点吗?它会导致错误,并将每一行视为单独的命令。
"stderr": "/bin/sh: line 1: --kubeconfig=~centos/.kube/config: No such file or directory\n/bin/sh: line 2: --server=ip-172-31-4-117.us-west-1.compute.internal:6443: command not found\n/bin/sh: line 3: --embed-certs=true: command not found\n/bin/sh: line 4: --certificate-authority=/etc/kubernetes/pki/ca.crt: No such file or directory",
"stderr_lines": [
"/bin/sh: line 1: --kubeconfig=~centos/.kube/config: No such file or directory",
"/bin/sh: line 2: --server=ip-172-31-4-117.us-west-1.compute.internal:6443: command not found",
"/bin/sh: line 3: --embed-certs=true: command not found",
"/bin/sh: line 4: --certificate-authority=/etc/kubernetes/pki/ca.crt: No such file or directory"
],发布于 2018-01-06 17:53:12
这是一种YAML语法,YAML中的缩进很重要。对于使用>标记的块标量,您应该使用单个缩进级别(否则YAML解析器会将缩进的行视为单独的行):
- name: "Update kubeconfig to set cluster"
shell: >
kubectl config set-cluster {{ item.cluster }}
--kubeconfig=~{{ item.account }}/.kube/config
--server={{ K8S_MASTER_HOSTNAME }}:{{ K8S_API_SERCURE_PORT }}
--embed-certs=true
--certificate-authority={{ K8S_CA_HOME }}/ca.crt
with_items: "{{ k8s_users }}"或者您可以使用普通样式的流标量:
- name: "Update kubeconfig to set cluster"
shell: kubectl config set-cluster {{ item.cluster }}
--kubeconfig=~{{ item.account }}/.kube/config
--server={{ K8S_MASTER_HOSTNAME }}:{{ K8S_API_SERCURE_PORT }}
--embed-certs=true
--certificate-authority={{ K8S_CA_HOME }}/ca.crt
with_items: "{{ k8s_users }}"https://stackoverflow.com/questions/48124622
复制相似问题