forked from easzlab/kubeasz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.yml
85 lines (72 loc) · 2.62 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
- import_tasks: debian.yml
when: 'ansible_distribution_file_variety in ["Debian"]'
- import_tasks: redhat.yml
when: 'ansible_distribution_file_variety in ["RedHat"]'
- import_tasks: suse.yml
when: 'ansible_distribution_file_variety in ["SUSE"]'
- import_tasks: redhat.yml
when: 'ansible_distribution in ["Anolis OS"]'
# 公共系统参数设置
- import_tasks: common.yml
- name: prepare some dirs
file: name={{ item }} state=directory
with_items:
- "{{ bin_dir }}"
- "{{ ca_dir }}"
- /root/.kube
- name: 写入环境变量$PATH
lineinfile:
dest: ~/.bashrc
state: present
regexp: 'custom PATH'
line: 'export PATH={{ bin_dir }}:$PATH # generated by kubeasz:custom PATH'
- name: ansible 控制端写入命令别名
lineinfile:
dest: ~/.bashrc
state: present
regexp: 'docker exec'
line: "alias dk='docker exec -it kubeasz' # generated by kubeasz"
when: "inventory_hostname == ansible_env.SSH_CLIENT.split(' ')[0]"
- name: 添加 local registry hosts 解析
lineinfile:
dest: /etc/hosts
state: present
regexp: 'easzlab.io.local'
line: "{{ ansible_env.SSH_CLIENT.split(' ')[0] }} easzlab.io.local"
# 设置节点hostname,calico 网络组件要求每个节点不一样的hostname
- name: 设置节点 hostname
hostname:
name: "{{ K8S_NODENAME }}"
use: systemd
when: "ENABLE_SETTING_HOSTNAME|bool"
# 设置节点名称{{ K8S_NODENAME }} /etc/hosts 解析
# 1.先确保第一个主节点做好解析
- name: 设置 k8s_nodename 在 master[0] 节点 /etc/hosts 地址解析
lineinfile:
dest: /etc/hosts
state: present
regexp: "{{ K8S_NODENAME }} .* generated by kubeasz"
line: "{{ inventory_hostname }} {{ K8S_NODENAME }} # generated by kubeasz"
delegate_to: "{{ groups.kube_master[0] }}"
when: "inventory_hostname != K8S_NODENAME"
# 2.然后复制给集群所有节点
- block:
- name: 获取 master[0] 节点由kubeasz 创建的 /etc/hosts 地址解析
shell: 'grep "generated by kubeasz" /etc/hosts|sort|uniq'
register: RESOLVE_K8S_NODENAME
delegate_to: "{{ groups.kube_master[0] }}"
- name: 删除 master[0] 节点由kubeasz 创建的 /etc/hosts 地址解析
lineinfile:
dest: /etc/hosts
state: absent
regexp: "generated by kubeasz"
delegate_to: "{{ groups.kube_master[0] }}"
- name: 设置 k8s_nodename 在所有节点的 /etc/hosts 地址解析
blockinfile:
path: /etc/hosts
block: |
{{ RESOLVE_K8S_NODENAME.stdout }}
marker: "### {mark} KUBEASZ MANAGED BLOCK"
delegate_to: "{{ item }}"
with_items: ["{{ groups.kube_master }}", "{{ groups.kube_node }}"]
run_once: true