Skip to content

Commit 4999b2b

Browse files
committed
调整去掉delegate_to deploy节点的任务
1 parent 70c1f8b commit 4999b2b

File tree

8 files changed

+60
-121
lines changed

8 files changed

+60
-121
lines changed

11.harbor.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
- hosts: harbor
55
roles:
6-
- { role: chrony, when: "hostvars[groups.deploy[0]]['NTP_ENABLED'] == 'yes' and NEW_INSTALL == 'yes'" }
6+
- { role: chrony, when: "NEW_INSTALL == 'yes' and groups['chrony']|length > 0" }
77
- { role: prepare, when: "NEW_INSTALL == 'yes'" }
88
- { role: docker, when: "NEW_INSTALL == 'yes'" }
99
- { role: harbor, when: "NEW_INSTALL == 'yes'" }
@@ -19,10 +19,10 @@
1919
- kube-node
2020
tasks:
2121
- name: Define 'harbor_host', a domain name
22-
set_fact: harbor_host="{{ hostvars[groups.harbor[0]]['HARBOR_DOMAIN'] }}"
22+
set_fact: harbor_host={{ hostvars[groups.harbor[0]]['HARBOR_DOMAIN'] }}
2323

2424
- name: Define 'harbor_host', an IP Addr
25-
set_fact: harbor_host="{{ groups['harbor'][0] }}"
25+
set_fact: harbor_host={{ groups['harbor'][0] }}
2626
when: hostvars[groups.harbor[0]]['HARBOR_DOMAIN'] == ''
2727

2828
- block:

roles/calico/tasks/main.yml

+30-46
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,38 @@
1-
- block:
2-
- name: 在deploy 节点创建相关目录
3-
file: name={{ item }} state=directory
4-
with_items:
5-
- /etc/calico/ssl
6-
- /opt/kube/kube-system/calico
7-
8-
- name: 创建calico 证书请求
9-
template: src=calico-csr.json.j2 dest=/etc/calico/ssl/calico-csr.json
10-
11-
- name: 创建 calico证书和私钥
12-
shell: "cd /etc/calico/ssl && {{ bin_dir }}/cfssl gencert \
13-
-ca={{ ca_dir }}/ca.pem \
14-
-ca-key={{ ca_dir }}/ca-key.pem \
15-
-config={{ ca_dir }}/ca-config.json \
16-
-profile=kubernetes calico-csr.json | {{ bin_dir }}/cfssljson -bare calico"
17-
18-
- name: get calico-etcd-secrets info
19-
shell: "{{ bin_dir }}/kubectl get secrets -n kube-system"
20-
register: secrets_info
21-
22-
- name: 创建 calico-etcd-secrets
23-
shell: "cd /etc/calico/ssl && \
24-
{{ bin_dir }}/kubectl create secret generic -n kube-system calico-etcd-secrets \
25-
--from-file=etcd-ca={{ ca_dir }}/ca.pem \
26-
--from-file=etcd-key=calico-key.pem \
27-
--from-file=etcd-cert=calico.pem"
28-
when: '"calico-etcd-secrets" not in secrets_info.stdout'
29-
30-
- name: 配置 calico DaemonSet yaml文件
31-
template: src=calico-{{ calico_ver_main }}.yaml.j2 dest=/opt/kube/kube-system/calico/calico.yaml
32-
33-
delegate_to: "{{ groups.deploy[0] }}"
34-
run_once: true
35-
36-
- name: node 节点创建calico 相关目录
1+
- name: 在节点创建相关目录
372
file: name={{ item }} state=directory
383
with_items:
394
- /etc/calico/ssl
405
- /etc/cni/net.d
416
- /opt/kube/images
7+
- /opt/kube/kube-system
428

9+
- name: 创建calico 证书请求
10+
template: src=calico-csr.json.j2 dest=/etc/calico/ssl/calico-csr.json
11+
12+
- name: 创建 calico证书和私钥
13+
shell: "cd /etc/calico/ssl && {{ bin_dir }}/cfssl gencert \
14+
-ca={{ ca_dir }}/ca.pem \
15+
-ca-key={{ ca_dir }}/ca-key.pem \
16+
-config={{ ca_dir }}/ca-config.json \
17+
-profile=kubernetes calico-csr.json | {{ bin_dir }}/cfssljson -bare calico"
18+
19+
- name: get calico-etcd-secrets info
20+
shell: "{{ bin_dir }}/kubectl get secrets -n kube-system"
21+
register: secrets_info
22+
run_once: true
23+
24+
- name: 创建 calico-etcd-secrets
25+
shell: "cd /etc/calico/ssl && \
26+
{{ bin_dir }}/kubectl create secret generic -n kube-system calico-etcd-secrets \
27+
--from-file=etcd-ca={{ ca_dir }}/ca.pem \
28+
--from-file=etcd-key=calico-key.pem \
29+
--from-file=etcd-cert=calico.pem"
30+
when: '"calico-etcd-secrets" not in secrets_info.stdout'
31+
run_once: true
32+
33+
- name: 配置 calico DaemonSet yaml文件
34+
template: src=calico-{{ calico_ver_main }}.yaml.j2 dest=/opt/kube/kube-system/calico.yaml
35+
4336
# 【可选】推送离线docker 镜像,可以忽略执行错误
4437
- block:
4538
- name: 检查是否已下载离线calico镜像
@@ -79,8 +72,7 @@
7972

8073
# 只需单节点执行一次
8174
- name: 运行 calico网络
82-
shell: "{{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/calico/ && sleep 5"
83-
delegate_to: "{{ groups.deploy[0] }}"
75+
shell: "{{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/calico.yaml"
8476
run_once: true
8577

8678
# 删除原有cni配置
@@ -96,13 +88,6 @@
9688
#- loopback
9789
- calicoctl
9890

99-
- name: 分发 calico 证书
100-
synchronize: src=/etc/calico/ssl/{{ item }} dest=/etc/calico/ssl/{{ item }}
101-
with_items:
102-
- calico.pem
103-
- calico-key.pem
104-
delegate_to: "{{ groups.deploy[0] }}"
105-
10691
- name: 准备 calicoctl配置文件
10792
template: src=calicoctl.cfg.j2 dest=/etc/calico/calicoctl.cfg
10893

@@ -111,7 +96,6 @@
11196
shell: "{{ bin_dir }}/kubectl get pod -n kube-system -o wide|grep 'calico-node'|grep ' {{ inventory_hostname }} '|awk '{print $3}'"
11297
register: pod_status
11398
until: pod_status.stdout == "Running"
114-
delegate_to: "{{ groups.deploy[0] }}"
11599
retries: 15
116100
delay: 15
117101
ignore_errors: true

roles/cilium/tasks/main.yml

+8-16
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
1-
- name: 在deploy 节点创建cilium 相关目录
2-
file: name=/opt/kube/kube-system/cilium state=directory
3-
delegate_to: "{{ groups.deploy[0] }}"
4-
run_once: true
5-
6-
- name: 配置 cilium DaemonSet yaml文件
7-
template: src=cilium.yaml.j2 dest=/opt/kube/kube-system/cilium/cilium.yaml
8-
tags: reconf
9-
delegate_to: "{{ groups.deploy[0] }}"
10-
run_once: true
11-
121
- name: 转换内核版本为浮点数
132
set_fact:
143
KERNEL_VER: "{{ ansible_kernel.split('-')[0].split('.')[0]|int + ansible_kernel.split('-')[0].split('.')[1]|int/100 }}"
154

165
- name: 检查内核版本>4.9
176
fail: msg="kernel {{ ansible_kernel }} is too old for cilium installing"
187
when: "KERNEL_VER|float <= 4.09"
19-
8+
209
- name: node 节点创建cilium 相关目录
2110
file: name={{ item }} state=directory
2211
with_items:
2312
- /etc/cni/net.d
2413
- /var/run/cilium
25-
- /opt/kube/images
14+
- /opt/kube/images
15+
- /opt/kube/kube-system
16+
17+
- name: 配置 cilium DaemonSet yaml文件
18+
template: src=cilium.yaml.j2 dest=/opt/kube/kube-system/cilium.yaml
19+
tags: reconf
2620

2721
- name: Optional-Mount BPF FS
2822
mount:
@@ -70,8 +64,7 @@
7064

7165
# 只需单节点执行一次
7266
- name: 运行 cilium网络
73-
shell: "{{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/cilium/ && sleep 5"
74-
delegate_to: "{{ groups.deploy[0] }}"
67+
shell: "{{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/cilium.yaml"
7568
run_once: true
7669

7770
# 删除原有cni配置
@@ -83,7 +76,6 @@
8376
shell: "{{ bin_dir }}/kubectl get pod -n kube-system -o wide|grep 'cilium'|grep ' {{ inventory_hostname }} '|awk '{print $3}'"
8477
register: pod_status
8578
until: pod_status.stdout == "Running"
86-
delegate_to: "{{ groups.deploy[0] }}"
8779
retries: 15
8880
delay: 8
8981
ignore_errors: true

roles/cilium/templates/cilium-csr.json.j2

-17
This file was deleted.

roles/flannel/tasks/main.yml

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
- name: 创建相关目录
2-
file: name=/opt/kube/kube-system state=directory
3-
4-
- name: 配置 flannel DaemonSet yaml文件
5-
template: src=kube-flannel.yaml.j2 dest=/opt/kube/kube-system/flannel.yaml
6-
7-
- name: 创建flannel cni 相关目录
1+
- name: 创建flannel 相关目录
82
file: name={{ item }} state=directory
93
with_items:
104
- /etc/cni/net.d
115
- /opt/kube/images
6+
- /opt/kube/kube-system
127

8+
- name: 配置 flannel DaemonSet yaml文件
9+
template: src=kube-flannel.yaml.j2 dest=/opt/kube/kube-system/flannel.yaml
10+
1311
- name: 下载flannel cni plugins
1412
copy: src={{ base_dir }}/bin/{{ item }} dest={{ bin_dir }}/{{ item }} mode=0755
1513
with_items:
@@ -58,7 +56,7 @@
5856

5957
# 只需单节点执行一次
6058
- name: 运行 flannel网络
61-
shell: "{{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/flannel.yaml && sleep 5"
59+
shell: "{{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/flannel.yaml"
6260
run_once: true
6361

6462
# 删除原有cni配置

roles/harbor/tasks/main.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@
2525
shell: "{{ bin_dir }}/docker load -i /data/harbor/harbor.{{ HARBOR_VER }}.tar.gz"
2626

2727
- name: 分发证书相关
28-
synchronize: src={{ ca_dir }}/{{ item }} dest={{ ca_dir }}/{{ item }}
28+
copy: src={{ base_dir }}/.cluster/ssl/{{ item }} dest={{ ca_dir }}/{{ item }}
2929
with_items:
3030
- ca.pem
3131
- ca-key.pem
3232
- ca-config.json
33-
delegate_to: "{{ groups.deploy[0] }}"
3433

3534
- name: 创建harbor证书请求
3635
template: src=harbor-csr.json.j2 dest={{ ca_dir }}/harbor-csr.json

roles/kube-ovn/tasks/main.yml

+7-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
- block:
2-
- name: 在deploy 节点创建相关目录
3-
file: name=/opt/kube/kube-ovn state=directory
4-
5-
- name: 配置 kube-ovn.yaml 文件
6-
template: src=kube-ovn.yaml.j2 dest=/opt/kube/kube-ovn/kube-ovn.yaml
7-
8-
- name: 配置 ovn.yaml 文件
9-
template: src=ovn.yaml.j2 dest=/opt/kube/kube-ovn/ovn.yaml
10-
11-
delegate_to: "{{ groups.deploy[0] }}"
12-
run_once: true
13-
141
- name: 创建相关目录
152
file: name={{ item }} state=directory
163
with_items:
174
- /etc/cni/net.d
185
- /opt/kube/images
6+
- /opt/kube/kube-ovn
7+
8+
- name: 配置 kube-ovn.yaml 文件
9+
template: src=kube-ovn.yaml.j2 dest=/opt/kube/kube-ovn/kube-ovn.yaml
10+
11+
- name: 配置 ovn.yaml 文件
12+
template: src=ovn.yaml.j2 dest=/opt/kube/kube-ovn/ovn.yaml
1913

2014
# 【可选】推送离线镜像,可以忽略执行错误
2115
- block:
@@ -59,7 +53,6 @@
5953
shell: "{{ bin_dir }}/kubectl label node {{ OVN_DB_NODE }} kube-ovn/role=master --overwrite && \
6054
{{ bin_dir }}/kubectl apply -f /opt/kube/kube-ovn/ovn.yaml && sleep 5 && \
6155
{{ bin_dir }}/kubectl apply -f /opt/kube/kube-ovn/kube-ovn.yaml"
62-
delegate_to: "{{ groups.deploy[0] }}"
6356
run_once: true
6457

6558
# 删除原有cni配置
@@ -71,8 +64,6 @@
7164
shell: "{{ bin_dir }}/kubectl get pod -n kube-ovn -o wide|grep 'kube-ovn-cni'|grep ' {{ inventory_hostname }} '|awk '{print $3}'"
7265
register: pod_status
7366
until: pod_status.stdout == "Running"
74-
delegate_to: "{{ groups.deploy[0] }}"
7567
retries: 15
7668
delay: 8
7769
ignore_errors: true
78-

roles/kube-router/tasks/main.yml

+5-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
- block:
2-
- name: 在deploy 节点创建相关目录
3-
file: name=/opt/kube/kube-system/kube-router state=directory
4-
5-
- name: 准备配置 kube-router DaemonSet (without IPVS)
6-
template: src=kuberouter.yaml.j2 dest=/opt/kube/kube-system/kube-router/kuberouter.yaml
7-
delegate_to: "{{ groups.deploy[0] }}"
8-
run_once: true
9-
101
- name: 创建cni 和kube-router 相关目录
112
file: name={{ item }} state=directory
123
with_items:
134
- /etc/cni/net.d
145
- /opt/kube/images
6+
- /opt/kube/kube-system
157

8+
- name: 准备配置 kube-router DaemonSet (without IPVS)
9+
template: src=kuberouter.yaml.j2 dest=/opt/kube/kube-system/kuberouter.yaml
10+
1611
- name: 下载cni plugins
1712
copy: src={{ base_dir }}/bin/{{ item }} dest={{ bin_dir }}/{{ item }} mode=0755
1813
with_items:
@@ -63,8 +58,7 @@
6358

6459
# 只需单节点执行一次
6560
- name: 运行 kube-router DaemonSet
66-
shell: "{{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/kube-router/ && sleep 5"
67-
delegate_to: "{{ groups.deploy[0] }}"
61+
shell: "{{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/kuberouter.yaml"
6862
run_once: true
6963

7064
# 删除原有cni配置
@@ -76,8 +70,6 @@
7670
shell: "{{ bin_dir }}/kubectl get pod -n kube-system -o wide|grep 'kube-router'|grep ' {{ inventory_hostname }} '|awk '{print $3}'"
7771
register: pod_status
7872
until: pod_status.stdout == "Running"
79-
delegate_to: "{{ groups.deploy[0] }}"
8073
retries: 15
8174
delay: 8
8275
ignore_errors: true
83-

0 commit comments

Comments
 (0)