This is the ansible yml, I run it on an ansible control node to apply flannel network of the master node. And I am a root user.
- name: Apply flannel network
shell: sudo kubectl apply -f /tmp/.ansible/files/kube-flannel.yml
And the ansible give me this error:
"unable to recognize \"/tmp/.ansible/files/kube-flannel.yml\": Get http://localhost:8080/api?timeout=32s: dial tcp [::1]:8080: connect: connection refused"]}
But,when I manually login the master node and run sudo kubectl apply -f /tmp/.ansible/files/kube-flannel.yml
it works without error.
root@PC:~# kubectl apply -f /tmp/.ansible/files/kube-flannel.yml
clusterrole.rbac.authorization.k8s.io/flannel created
clusterrolebinding.rbac.authorization.k8s.io/flannel created
serviceaccount/flannel created
configmap/kube-flannel-cfg created
daemonset.extensions/kube-flannel-ds-amd64 created
daemonset.extensions/kube-flannel-ds-arm64 created
daemonset.extensions/kube-flannel-ds-arm created
daemonset.extensions/kube-flannel-ds-ppc64le created
daemonset.extensions/kube-flannel-ds-s390x created
The final qustion is, how to fixs the ansible error?