kubeasz/roles/deploy/tasks/main.yml

81 lines
2.7 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

- name: prepare some dirs
file: name={{ item }} state=directory
with_items:
- "{{ base_dir }}/.cluster/ssl"
- "{{ base_dir }}/.cluster/backup"
- name: 本地设置 bin 目录权限
file: path={{ base_dir }}/bin state=directory mode=0755 recurse=yes
# 注册变量p根据p的stat信息判断是否已经生成过ca证书如果没有下一步生成证书
# 如果已经有ca证书为了保证整个安装的幂等性跳过证书生成的步骤
- name: 读取ca证书stat信息
stat: path="{{ base_dir }}/.cluster/ssl/ca.pem"
register: p
- name: 准备CA配置文件和签名请求
template: src={{ item }}.j2 dest={{ base_dir }}/.cluster/ssl/{{ item }}
with_items:
- "ca-config.json"
- "ca-csr.json"
when: p.stat.isreg is not defined
- name: 生成 CA 证书和私钥
when: p.stat.isreg is not defined
shell: "cd {{ base_dir }}/.cluster/ssl && \
{{ base_dir }}/bin/cfssl gencert -initca ca-csr.json | {{ base_dir }}/bin/cfssljson -bare ca"
#----------- 创建admin kubectl kubeconfig文件: /root/.kube/config
- import_tasks: create-kubectl-kubeconfig.yml
tags: create_kctl_cfg
#-----------可选创建只读kubeconfig文件: /root/.kube/read.config
- import_tasks: create-kubectl-ro-kubeconfig.yml
when: "CREATE_READONLY_KUBECONFIG"
#------------创建配置文件: kube-proxy.kubeconfig
- import_tasks: create-kube-proxy-kubeconfig.yml
#------------创建配置文件: kube-controller-manager.kubeconfig
- import_tasks: create-kube-controller-manager-kubeconfig.yml
#------------创建配置文件: kube-scheduler.kubeconfig
- import_tasks: create-kube-scheduler-kubeconfig.yml
# ansible 控制端一些易用性配置
- name: 本地创建 easzctl 工具的软连接
file: src={{ base_dir }}/tools/easzctl dest=/usr/bin/easzctl state=link
- name: ansible 控制端创建 kubectl 软链接
file: src={{ base_dir }}/bin/kubectl dest=/usr/bin/kubectl state=link
ignore_errors: true
# 注册变量以判断是否容器化运行ansible控制端如果容器化运行那么进程数小于50
- name: 注册变量以判断是否容器化运行ansible控制端
shell: "ps aux|wc -l"
register: procs
- name: ansible 控制端写入环境变量$PATH
lineinfile:
dest: ~/.bashrc
state: present
regexp: 'kubeasz'
line: 'export PATH={{ base_dir }}/bin/:$PATH # generated by kubeasz'
when: "procs.stdout|int > 50"
ignore_errors: true
- name: ansible 控制端添加 kubectl 自动补全
lineinfile:
dest: ~/.bashrc
state: present
regexp: 'kubectl completion'
line: 'source <(kubectl completion bash)'
when: "procs.stdout|int > 50"
ignore_errors: true
- name: pip install netaddr
pip:
name: netaddr
when: "procs.stdout|int > 50"
ignore_errors: true