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

81 lines
2.2 KiB
YAML
Raw Normal View History

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
2021-04-09 08:35:12 +08:00
- name: prepare some dirs
2019-06-28 21:16:13 +08:00
file: name={{ item }} state=directory
with_items:
2021-04-09 08:35:12 +08:00
- "/etc/l4lb/sbin"
- "/etc/l4lb/logs"
- "/etc/l4lb/conf"
- "/etc/keepalived"
2019-06-28 21:16:13 +08:00
2021-04-09 08:35:12 +08:00
- name: 下载二进制文件l4lb(nginx)
copy: src={{ base_dir }}/bin/nginx dest=/etc/l4lb/sbin/l4lb mode=0755
2019-11-24 21:30:31 +08:00
2021-04-09 08:35:12 +08:00
- name: 创建l4lb的配置文件
template: src=l4lb.conf.j2 dest=/etc/l4lb/conf/l4lb.conf
2019-11-24 21:30:31 +08:00
tags: restart_lb
2021-04-09 08:35:12 +08:00
- name: 创建l4lb的systemd unit文件
template: src=l4lb.service.j2 dest=/etc/systemd/system/l4lb.service
2019-11-24 21:30:31 +08:00
tags: restart_lb
2021-04-09 08:35:12 +08:00
- name: 开机启用l4lb服务
shell: systemctl enable l4lb
2019-11-24 21:30:31 +08:00
ignore_errors: true
2019-06-28 21:16:13 +08:00
2021-04-09 08:35:12 +08:00
- name: 开启l4lb服务
shell: systemctl daemon-reload && systemctl restart l4lb
ignore_errors: true
tags: restart_lb
2019-02-07 15:10:49 +08:00
2021-04-09 08:35:12 +08:00
- name: 以轮询的方式等待l4lb服务启动
shell: "systemctl status l4lb.service|grep Active"
register: svc_status
until: '"running" in svc_status.stdout'
retries: 3
delay: 3
2019-02-07 15:10:49 +08:00
tags: restart_lb
2021-04-09 08:35:12 +08:00
- name: 下载二进制文件keepalived
copy: src={{ base_dir }}/bin/keepalived dest=/usr/local/sbin/keepalived mode=0755
- name: 配置 keepalived 主节点
template: src=keepalived-master.conf.j2 dest=/etc/keepalived/keepalived.conf
when: LB_ROLE == "master"
2019-02-07 15:10:49 +08:00
tags: restart_lb
2021-04-09 08:35:12 +08:00
- name: 配置 keepalived 备节点
template: src=keepalived-backup.conf.j2 dest=/etc/keepalived/keepalived.conf
when: LB_ROLE == "backup"
tags: restart_lb
2019-02-07 15:10:49 +08:00
2021-04-09 08:35:12 +08:00
- name: 创建keepalived的systemd unit文件
template: src=keepalived.service.j2 dest=/etc/systemd/system/keepalived.service
2019-02-07 15:10:49 +08:00
tags: restart_lb
- name: 开机启用keepalived服务
shell: systemctl enable keepalived
ignore_errors: true
2021-04-09 08:35:12 +08:00
- name: 开启keepalived服务
shell: systemctl daemon-reload && systemctl restart keepalived
ignore_errors: true
tags: restart_lb
- name: 以轮询的方式等待keepalived服务启动
shell: "systemctl status keepalived.service|grep Active"
register: svc_status
until: '"running" in svc_status.stdout'
retries: 3
delay: 3
2019-02-07 15:10:49 +08:00
tags: restart_lb