kubeasz/roles/prepare/tasks/main.yml

72 lines
2.1 KiB
YAML

- 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"
# 设置节点名称{{ K8S_NODENAME }} /etc/hosts 解析
# 1.先确保第一个主节点做好解析
# 2.然后复制给集群所有节点
- 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"
- name: 获取 master[0] 节点由kubeasz 创建的 /etc/hosts 地址解析
shell: 'grep "generated by kubeasz" /etc/hosts'
register: RESOLVE_K8S_NODENAME
delegate_to: "{{ groups.kube_master[0] }}"
run_once: true
#- debug: var="RESOLVE_K8S_NODENAME.stdout"
# run_once: true
- name: 设置 /etc/hosts 地址解析
blockinfile:
path: /etc/hosts
block: |
{{ RESOLVE_K8S_NODENAME.stdout }}
when: "inventory_hostname != groups.kube_master[0]"