mirror of https://github.com/easzlab/kubeasz.git
87 lines
2.7 KiB
YAML
87 lines
2.7 KiB
YAML
- import_tasks: debian.yml
|
||
when: 'ansible_distribution_file_variety in ["Debian"]'
|
||
|
||
- import_tasks: redhat.yml
|
||
# when: 'ansible_distribution_file_variety in ["RedHat"]'
|
||
when: ansible_distribution_file_variety in ["RedHat"] or ansible_distribution in ["CentOS"]
|
||
|
||
- 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
|