2017-12-15 10:25:32 +08:00
|
|
|
|
# 先拉取下节点的ansible setup信息,起到缓存效果,否则后续when 判断可能失败
|
|
|
|
|
- name: 缓存ansilbe setup信息
|
|
|
|
|
setup: gather_subset=min
|
|
|
|
|
|
2017-11-26 09:34:33 +08:00
|
|
|
|
- name: apt更新缓存刷新
|
|
|
|
|
apt: update_cache=yes cache_valid_time=72000
|
2017-12-14 23:18:57 +08:00
|
|
|
|
when: ansible_distribution == "Ubuntu" and ansible_distribution_major_version == "16"
|
2017-11-26 09:34:33 +08:00
|
|
|
|
|
2017-12-15 10:25:32 +08:00
|
|
|
|
- name: apt安装 haproxy
|
2017-11-26 09:34:33 +08:00
|
|
|
|
apt: name=haproxy state=latest
|
2017-12-14 23:18:57 +08:00
|
|
|
|
when: ansible_distribution == "Ubuntu" and ansible_distribution_major_version == "16"
|
2017-12-14 23:09:56 +08:00
|
|
|
|
|
2017-12-15 10:25:32 +08:00
|
|
|
|
- name: yum安装 haproxy
|
2017-12-14 23:09:56 +08:00
|
|
|
|
yum: name=haproxy state=latest
|
2017-12-14 23:18:57 +08:00
|
|
|
|
when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "7"
|
2017-11-11 19:14:21 +08:00
|
|
|
|
|
|
|
|
|
- name: 创建haproxy配置目录
|
|
|
|
|
file: name=/etc/haproxy state=directory
|
|
|
|
|
|
|
|
|
|
- name: 配置 haproxy
|
|
|
|
|
template: src=haproxy.cfg.j2 dest=/etc/haproxy/haproxy.cfg
|
|
|
|
|
|
2017-12-15 10:25:32 +08:00
|
|
|
|
- name: apt安装 keepalived
|
2017-11-26 09:34:33 +08:00
|
|
|
|
apt: name=keepalived state=latest
|
2017-12-14 23:18:57 +08:00
|
|
|
|
when: ansible_distribution == "Ubuntu" and ansible_distribution_major_version == "16"
|
2017-12-14 23:09:56 +08:00
|
|
|
|
|
2017-12-15 10:25:32 +08:00
|
|
|
|
- name: yum安装 keepalived
|
2017-12-14 23:09:56 +08:00
|
|
|
|
yum: name=keepalived state=latest
|
2017-12-14 23:18:57 +08:00
|
|
|
|
when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "7"
|
2017-11-11 19:14:21 +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"
|
|
|
|
|
|
|
|
|
|
- name: 配置 keepalived 备节点
|
|
|
|
|
template: src=keepalived-backup.conf.j2 dest=/etc/keepalived/keepalived.conf
|
|
|
|
|
when: LB_ROLE == "backup"
|
|
|
|
|
|
|
|
|
|
- name: 重启haproxy服务
|
|
|
|
|
shell: systemctl enable haproxy && systemctl restart haproxy
|
|
|
|
|
|
|
|
|
|
- name: 重启keepalived服务
|
|
|
|
|
shell: systemctl enable keepalived && systemctl restart keepalived
|