kubeasz/roles/deploy/tasks/main.yml

82 lines
2.6 KiB
YAML
Raw Normal View History

2017-11-11 19:14:21 +08:00
- name: prepare some dirs
file: name={{ item }} state=directory
with_items:
2020-12-25 11:53:00 +08:00
- "{{ cluster_dir }}/ssl"
- "{{ cluster_dir }}/backup"
2021-01-11 11:12:14 +08:00
- "{{ cluster_dir }}/yml"
2021-01-07 09:30:50 +08:00
- "~/.kube"
2017-11-11 19:14:21 +08:00
- name: 本地设置 bin 目录权限
file: path={{ base_dir }}/bin state=directory mode=0755 recurse=yes
# 注册变量p根据p的stat信息判断是否已经生成过ca证书如果没有下一步生成证书
# 如果已经有ca证书为了保证整个安装的幂等性跳过证书生成的步骤
- name: 读取ca证书stat信息
2020-12-25 11:53:00 +08:00
stat: path="{{ cluster_dir }}/ssl/ca.pem"
register: p
2017-11-11 19:14:21 +08:00
- name: 准备CA配置文件和签名请求
2020-12-25 11:53:00 +08:00
template: src={{ item }}.j2 dest={{ cluster_dir }}/ssl/{{ item }}
with_items:
- "ca-config.json"
- "ca-csr.json"
when: p.stat.isreg is not defined
2017-11-11 19:14:21 +08:00
- name: 生成 CA 证书和私钥
when: p.stat.isreg is not defined
2020-12-25 11:53:00 +08:00
shell: "cd {{ cluster_dir }}/ssl && \
{{ base_dir }}/bin/cfssl gencert -initca ca-csr.json | {{ base_dir }}/bin/cfssljson -bare ca"
2017-11-11 19:14:21 +08:00
#----------- 创建配置文件: /root/.kube/config
- import_tasks: create-kubectl-kubeconfig.yml
tags: create_kctl_cfg
#----------- 创建个性化客户端配置文件
- import_tasks: add-custom-kubectl-kubeconfig.yml
tags: add-kcfg
when: "ADD_KCFG|bool"
#------------创建配置文件: 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: 本地创建 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
2019-06-24 00:05:25 +08:00
- name: ansible 控制端写入环境变量$PATH
lineinfile:
dest: ~/.bashrc
state: present
2022-06-11 10:48:55 +08:00
regexp: 'custom PATH'
line: 'export PATH={{ base_dir }}/bin/:$PATH # custom PATH generated by kubeasz'
ignore_errors: true
- name: ansible 控制端写入命令别名
lineinfile:
dest: ~/.bashrc
state: present
regexp: 'docker exec'
line: "alias dek='docker exec -it kubeasz' # custom PATH generated by kubeasz"
ignore_errors: true
2019-05-28 23:46:22 +08:00
- name: ansible 控制端添加 kubectl 自动补全
lineinfile:
dest: ~/.bashrc
state: present
regexp: 'kubectl completion'
2022-06-11 10:48:55 +08:00
line: 'source <(kubectl completion bash) # generated by kubeasz'
2019-05-28 23:46:22 +08:00
ignore_errors: true