diff --git a/roles/lb/tasks/main.yml b/roles/lb/tasks/main.yml index 2dcb1f8..c86f176 100644 --- a/roles/lb/tasks/main.yml +++ b/roles/lb/tasks/main.yml @@ -17,8 +17,9 @@ - name: 创建haproxy配置目录 file: name=/etc/haproxy state=directory -- name: 创建haproxy工作目录 - file: name=/run/haproxy state=directory owner=haproxy group=haproxy +- 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 @@ -48,7 +49,7 @@ when: LB_ROLE == "backup" - name: 重启haproxy服务 - shell: systemctl enable haproxy && systemctl restart haproxy + shell: systemctl enable haproxy && systemctl daemon-reload && systemctl restart haproxy - name: 重启keepalived服务 shell: systemctl enable keepalived && systemctl restart keepalived diff --git a/roles/lb/templates/haproxy.service.j2 b/roles/lb/templates/haproxy.service.j2 new file mode 100644 index 0000000..31ff557 --- /dev/null +++ b/roles/lb/templates/haproxy.service.j2 @@ -0,0 +1,13 @@ +[Unit] +Description=HAProxy Load Balancer +After=syslog.target network.target + +[Service] +EnvironmentFile=/etc/sysconfig/haproxy +ExecStartPre=/usr/bin/mkdir /run/haproxy +ExecStart=/usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid $OPTIONS +ExecReload=/bin/kill -USR2 $MAINPID +KillMode=mixed + +[Install] +WantedBy=multi-user.target diff --git a/roles/prepare/tasks/main.yml b/roles/prepare/tasks/main.yml index 518fc3e..9b4726c 100644 --- a/roles/prepare/tasks/main.yml +++ b/roles/prepare/tasks/main.yml @@ -35,3 +35,4 @@ - name: 关闭 selinux shell: "setenforce 0 && echo SELINUX=disabled > /etc/selinux/config" when: ansible_distribution == "CentOS" + ignore_errors: true