kubeasz/roles/ex-lb/tasks/main.yml

70 lines
2.0 KiB
YAML
Raw Normal View History

2019-05-30 21:37:01 +08:00
# ex-lb 节点成员不能同时是 kube-node 节点,因为它们都需要安装 haproxy
- name: fail info1
fail: msg="an 'ex-lb' node CAN NOT be a 'kube-node' node at the same time"
when: "inventory_hostname in groups['kube-node']"
2019-02-07 15:10:49 +08:00
# 自动设置LB节点变量'LB_IF'
- name: 注册变量 LB_IF_TMP
shell: "ip a|grep '{{ inventory_hostname }}/'|awk '{print $NF}'"
register: LB_IF_TMP
2019-05-30 21:37:01 +08:00
tags: restart_lb
2019-02-07 15:10:49 +08:00
- name: 设置变量 LB_IF
2019-05-30 21:37:01 +08:00
set_fact: LB_IF={{ LB_IF_TMP.stdout }}
tags: restart_lb
2019-02-07 15:10:49 +08:00
- name: apt更新缓存刷新
apt: update_cache=yes cache_valid_time=72000
2019-05-30 21:37:01 +08:00
when: 'ansible_distribution in ["Ubuntu","Debian"]'
2019-02-07 15:10:49 +08:00
- name: 安装 haproxy
2019-04-03 15:02:05 +08:00
package: name=haproxy state=present
2019-02-07 15:10:49 +08:00
- name: 创建haproxy配置目录
file: name=/etc/haproxy state=directory
- name: 修改centos的haproxy.service
template: src=haproxy.service.j2 dest=/usr/lib/systemd/system/haproxy.service
2019-05-30 21:37:01 +08:00
when: 'ansible_distribution in ["CentOS","RedHat","Amazon"]'
2019-02-07 15:10:49 +08:00
tags: restart_lb
- name: 配置 haproxy
template: src=haproxy.cfg.j2 dest=/etc/haproxy/haproxy.cfg
tags: restart_lb
- name: 安装 keepalived
2019-04-03 15:02:05 +08:00
package: name=keepalived state=present
2019-02-07 15:10:49 +08:00
- name: 创建keepalived配置目录
file: name=/etc/keepalived state=directory
- name: 配置 keepalived 主节点
template: src=keepalived-master.conf.j2 dest=/etc/keepalived/keepalived.conf
when: LB_ROLE == "master"
tags: restart_lb
- name: 配置 keepalived 备节点
template: src=keepalived-backup.conf.j2 dest=/etc/keepalived/keepalived.conf
when: LB_ROLE == "backup"
tags: restart_lb
- name: daemon-reload for haproxy.service
shell: systemctl daemon-reload
tags: restart_lb
- name: 开机启用haproxy服务
shell: systemctl enable haproxy
ignore_errors: true
- name: 重启haproxy服务
shell: systemctl restart haproxy
tags: restart_lb
- name: 开机启用keepalived服务
shell: systemctl enable keepalived
ignore_errors: true
- name: 重启keepalived服务
shell: systemctl restart keepalived
tags: restart_lb