kubeasz/roles/lb/tasks/main.yml

59 lines
2.1 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.

# 先拉取下节点的ansible setup信息起到缓存效果否则后续when 判断可能失败
- name: 缓存ansilbe setup信息
setup: gather_subset=min
- name: apt更新缓存刷新
apt: update_cache=yes cache_valid_time=72000
when: ansible_distribution == "Ubuntu" and ansible_distribution_major_version == "16"
- name: apt安装 haproxy
apt: name=haproxy state=latest
when: ansible_distribution == "Ubuntu" and ansible_distribution_major_version == "16"
- name: yum安装 haproxy
yum: name=haproxy state=latest
when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "7"
- name: 创建haproxy配置目录
file: name=/etc/haproxy state=directory
- name: 修改centos的haproxy.service
template: src=haproxy.service.j2 dest=/usr/lib/systemd/system/haproxy.service
when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "7"
- name: 配置 haproxy
template: src=haproxy.cfg.j2 dest=/etc/haproxy/haproxy.cfg
- name: apt安装 keepalived
apt: name=keepalived state=latest
when: ansible_distribution == "Ubuntu" and ansible_distribution_major_version == "16"
- name: yum安装 keepalived
yum: name=keepalived state=latest
when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "7"
# CentOS 需要安装psmisc 才能使用命令killall它在keepalive的监测脚本中使用到
- name: yum安装 psmisc
yum: name=psmisc state=latest
when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "7"
- 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"
- name: 配置 keepalived 备节点
template: src=keepalived-backup.conf.j2 dest=/etc/keepalived/keepalived.conf
when: LB_ROLE == "backup"
- name: daemon-reload for haproxy.service
shell: systemctl daemon-reload
- name: 重启haproxy服务
shell: systemctl enable haproxy && systemctl restart haproxy
- name: 重启keepalived服务
shell: systemctl enable keepalived && systemctl restart keepalived