2018-11-26 21:56:22 +08:00
|
|
|
# 自动设置LB节点变量'LB_IF'
|
|
|
|
- name: 注册变量 LB_IF_TMP
|
2018-12-13 16:43:30 +08:00
|
|
|
shell: "ip a|grep '{{ inventory_hostname }}/'|awk '{print $NF}'"
|
2018-11-26 21:56:22 +08:00
|
|
|
register: LB_IF_TMP
|
2019-02-24 12:56:47 +08:00
|
|
|
tags: restart_lb
|
2018-11-26 21:56:22 +08:00
|
|
|
|
|
|
|
- name: 设置变量 LB_IF
|
|
|
|
set_fact: LB_IF="{{ LB_IF_TMP.stdout }}"
|
2019-02-24 12:56:47 +08:00
|
|
|
tags: restart_lb
|
2018-11-26 21:56:22 +08:00
|
|
|
|
2017-11-26 09:34:33 +08:00
|
|
|
- name: apt更新缓存刷新
|
|
|
|
apt: update_cache=yes cache_valid_time=72000
|
2018-08-02 17:25:25 +08:00
|
|
|
when: ansible_distribution == "Ubuntu" and ansible_distribution_major_version|int >= 16
|
2017-11-26 09:34:33 +08:00
|
|
|
|
2019-02-07 15:23:59 +08:00
|
|
|
- name: 安装 haproxy
|
2019-04-03 15:02:05 +08:00
|
|
|
package: name=haproxy state=present
|
2017-11-11 19:14:21 +08:00
|
|
|
|
|
|
|
- name: 创建haproxy配置目录
|
|
|
|
file: name=/etc/haproxy state=directory
|
|
|
|
|
2017-12-15 19:56:26 +08:00
|
|
|
- name: 修改centos的haproxy.service
|
|
|
|
template: src=haproxy.service.j2 dest=/usr/lib/systemd/system/haproxy.service
|
2019-01-03 20:21:39 +08:00
|
|
|
when: (ansible_distribution == "CentOS" or ansible_distribution == "RedHat") and ansible_distribution_major_version == "7"
|
2018-09-04 00:05:38 +08:00
|
|
|
tags: restart_lb
|
2017-12-15 16:26:37 +08:00
|
|
|
|
2017-11-11 19:14:21 +08:00
|
|
|
- name: 配置 haproxy
|
|
|
|
template: src=haproxy.cfg.j2 dest=/etc/haproxy/haproxy.cfg
|
2018-09-04 00:05:38 +08:00
|
|
|
tags: restart_lb
|
2017-11-11 19:14:21 +08:00
|
|
|
|
2019-02-07 15:23:59 +08:00
|
|
|
- name: 安装 keepalived
|
2019-04-03 15:02:05 +08:00
|
|
|
package: name=keepalived state=present
|
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"
|
2018-09-04 00:05:38 +08:00
|
|
|
tags: restart_lb
|
2017-11-11 19:14:21 +08:00
|
|
|
|
|
|
|
- name: 配置 keepalived 备节点
|
|
|
|
template: src=keepalived-backup.conf.j2 dest=/etc/keepalived/keepalived.conf
|
|
|
|
when: LB_ROLE == "backup"
|
2018-09-04 00:05:38 +08:00
|
|
|
tags: restart_lb
|
2017-11-11 19:14:21 +08:00
|
|
|
|
2017-12-15 20:22:31 +08:00
|
|
|
- name: daemon-reload for haproxy.service
|
|
|
|
shell: systemctl daemon-reload
|
2018-09-04 00:05:38 +08:00
|
|
|
tags: restart_lb
|
2017-12-15 20:22:31 +08:00
|
|
|
|
2018-04-10 18:33:24 +08:00
|
|
|
- name: 开机启用haproxy服务
|
|
|
|
shell: systemctl enable haproxy
|
|
|
|
ignore_errors: true
|
|
|
|
|
2017-11-11 19:14:21 +08:00
|
|
|
- name: 重启haproxy服务
|
2018-04-10 18:33:24 +08:00
|
|
|
shell: systemctl restart haproxy
|
2018-09-04 00:05:38 +08:00
|
|
|
tags: restart_lb
|
2018-04-10 18:33:24 +08:00
|
|
|
|
|
|
|
- name: 开机启用keepalived服务
|
|
|
|
shell: systemctl enable keepalived
|
|
|
|
ignore_errors: true
|
2017-11-11 19:14:21 +08:00
|
|
|
|
|
|
|
- name: 重启keepalived服务
|
2018-04-10 18:33:24 +08:00
|
|
|
shell: systemctl restart keepalived
|
2018-09-04 00:05:38 +08:00
|
|
|
tags: restart_lb
|