-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
main.yml
63 lines (52 loc) · 2.15 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
- name: prepare some dirs
file: name={{ item }} state=directory
with_items:
- "{{ cluster_dir }}/ssl"
- "{{ cluster_dir }}/backup"
- "{{ cluster_dir }}/yml"
- "~/.kube"
- name: 本地设置 bin 目录权限
file: path={{ base_dir }}/bin state=directory mode=0755 recurse=yes
# 注册变量p,根据p的stat信息判断是否已经生成过ca证书,如果没有,下一步生成证书
# 如果已经有ca证书,为了保证整个安装的幂等性,跳过证书生成的步骤
- name: 读取ca证书stat信息
stat: path="{{ cluster_dir }}/ssl/ca.pem"
register: p
tags: force_change_certs
- name: 准备CA配置文件和签名请求
template: src={{ item }}.j2 dest={{ cluster_dir }}/ssl/{{ item }}
with_items:
- "ca-config.json"
- "ca-csr.json"
when: "p.stat.isreg is not defined or CHANGE_CA|bool"
tags: force_change_certs
- name: 生成 CA 证书和私钥
when: "p.stat.isreg is not defined or CHANGE_CA|bool"
tags: force_change_certs
shell: "cd {{ cluster_dir }}/ssl && \
{{ base_dir }}/bin/cfssl gencert -initca ca-csr.json | {{ base_dir }}/bin/cfssljson -bare ca"
#----------- 创建配置文件: kubectl.kubeconfig
- import_tasks: create-kubectl-kubeconfig.yml
tags: create_kctl_cfg, force_change_certs
#----------- 创建个性化客户端配置文件
- import_tasks: add-custom-kubectl-kubeconfig.yml
tags: add-kcfg, force_change_certs
when: "ADD_KCFG|bool"
#------------创建配置文件: kube-proxy.kubeconfig
- import_tasks: create-kube-proxy-kubeconfig.yml
tags: force_change_certs
#------------创建配置文件: kube-controller-manager.kubeconfig
- import_tasks: create-kube-controller-manager-kubeconfig.yml
tags: force_change_certs
#------------创建配置文件: kube-scheduler.kubeconfig
- import_tasks: create-kube-scheduler-kubeconfig.yml
tags: force_change_certs
# ansible 控制端一些易用性配置
- name: 本地创建 ezdown/ezctl 工具的软连接
file: src={{ base_dir }}/{{ item }} dest=/usr/bin/{{ item }} state=link
with_items:
- ezdown
- ezctl
- name: ansible 控制端创建 kubectl 软链接
file: src={{ base_dir }}/bin/kubectl dest=/usr/bin/kubectl state=link
ignore_errors: true