# kube-node 节点成员不能同时是 ex-lb 节点,因为它们都需要安装 haproxy - name: fail info1 fail: msg="an 'kube-node' node CAN NOT be a 'ex-lb' node at the same time" when: "inventory_hostname in groups['ex-lb']" tags: restart_lb - name: 安装 haproxy package: name=haproxy state=present - 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 in ["CentOS","RedHat","Amazon"]' tags: restart_lb - name: 配置 haproxy template: src=haproxy.cfg.j2 dest=/etc/haproxy/haproxy.cfg tags: restart_lb - name: daemon-reload for haproxy.service shell: systemctl daemon-reload tags: restart_lb - name: 开机启用haproxy服务 shell: systemctl enable haproxy ignore_errors: true - name: 停止haproxy服务 shell: systemctl stop haproxy tags: restart_lb - name: 开启haproxy服务 shell: systemctl start haproxy when: "groups['kube-master']|length > 1" tags: restart_lb