---
# This playbook will patch the application servers behind the load balancer
# one at a time.

- hosts: appservers
  serial: 1

# These tasks run before applying the update to each host
  pre_tasks:
  - name: pull the server from the load balancer
    haproxy: 'state=disabled backend=app host={{ inventory_hostname }} socket=/var/lib/haproxy/stats'
    delegate_to: "{{ item }}"
    with_items: '{{groups.lbservers}}'
  
  roles:
  - common
  - jboss
  
  tasks:
  - name: apply all available patches
    yum:
      name: '*'
      state: latest
  
  - name: restart server
    shell: sleep 2 && shutdown -r now "Patched with Ansible"
    async: 1
    poll: 0
    ignore_errors: true
  
  - name: wait for server to come back
    local_action: wait_for host={{ inventory_hostname }} state=started delay=30 timeout=300
    sudo: false
  
  post_tasks:
  - name: wait for jboss to come back up
    wait_for: 'host={{ inventory_hostname }} port=8080 state=started timeout=600'
  
  - name: put the server back in the load balancer
    haproxy: 'state=enabled backend=app host={{ inventory_hostname }} socket=/var/lib/haproxy/stats'
    delegate_to: "{{ item }}"
    with_items: groups.lbservers
    

Add playbook to patch and reboot servers behind the load balancer
Add playbook to patch and reboot servers behind the load balancer
