- name: 获取所有已经创建的POD信息 command: "{{ base_dir }}/bin/kubectl get pod --all-namespaces" register: pod_info connection: local run_once: true - name: 获取已下载离线镜像信息 command: "ls {{ base_dir }}/down" register: download_info connection: local run_once: true - import_tasks: coredns.yml when: '"coredns" not in pod_info.stdout and dns_install == "yes"' - import_tasks: metrics-server.yml when: '"metrics-server" not in pod_info.stdout and metricsserver_install == "yes"' - import_tasks: dashboard.yml when: '"kubernetes-dashboard" not in pod_info.stdout and dashboard_install == "yes"' - import_tasks: ingress.yml when: '"traefik" not in pod_info.stdout and ingress_install == "yes"' - import_tasks: prometheus.yml when: '"kube-prometheus-operator" not in pod_info.stdout and prom_install == "yes"' #- block: # - block: # - name: 尝试推送离线 metallb镜像(若执行失败,可忽略) # copy: src={{ base_dir }}/down/{{ metallb_offline }} dest=/opt/kube/images/{{ metallb_offline }} # when: 'metallb_offline in download_info.stdout' # # - name: 获取metallb离线镜像推送情况 # command: "ls /opt/kube/images" # register: image_info # # - name: 导入 metallb的离线镜像(若执行失败,可忽略) # shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ metallb_offline }}" # when: 'metallb_offline in image_info.stdout and CONTAINER_RUNTIME == "docker"' # # - name: 导入 metallb的离线镜像(若执行失败,可忽略) # shell: "{{ bin_dir }}/ctr -n=k8s.io images import /opt/kube/images/{{ metallb_offline }}" # when: 'metallb_offline in image_info.stdout and CONTAINER_RUNTIME == "containerd"' # # - name: 生成 metallb 相关 manifests # template: src=metallb/{{ item }}.j2 dest=/opt/kube/kube-system/{{ item }} # with_items: # - "metallb.yaml" # - "{{ metallb_protocol }}.yaml" # # - name: 创建 metallb controller 部署 # shell: "{{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/metallb.yaml && \ # {{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/{{ metallb_protocol }}.yaml" # run_once: true # when: '"metallb" not in pod_info.stdout and metallb_install == "yes"' # ignore_errors: true