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