--- # This Playbook does utility stuff's like adding a webserver into the pool, etc.. - name: Add server to LB lineinfile: dest=/etc/haproxy/haproxy.cfg state=present regexp="${ansible_hostname}" line="server ${ansible_hostname} ${ansible_eth0.ipv4.address}:${httpd_port}" delegate_to: ${lbserver} register: last_run tags: add - name: Reload the haproxy service: name=haproxy state=reloaded delegate_to: ${lbserver} only_if: ${last_run.changed} tags: add - name: Remove the code from server command: rm -rf /var/www/html/* tags: remove - name: Remove server from LB lineinfile: dest=/etc/haproxy/haproxy.cfg state=absent regexp="${ansible_hostname}" delegate_to: $item with_items: ${groups.lbservers}} register: last_run tags: remove - name: disable the server in haproxy shell: echo "disable server myapplb/${ansible_hostname}" | socat stdio /var/lib/haproxy/stats delegate_to: $item with_items: ${groups.lbservers}} tags: remove - name: Remove the httpd package yum: name=httpd state=absent tags: remove