Last Updated: February 25, 2016
· mpdehaan

Talk to a load balancer

Suppose you have a script which takes a given node out of a load balancer rotation that takes the name of a host in order to execute that load balancer change. How might that work?


- hosts: all
  serial: 5


  - name: take the machine out of rotation
    action: command echo taking out of rotation $inventory_hostname

# here's an alternate notation if you are delegating to, you can   use 'local_action' 
# instead of 'action' and leave off the 'delegate_to' part.
# - local_action: command echo taking out of rotation     $inventory_hostname

  - name: do several things on the actual host
    action: command echo hi mom $inventory_hostname

  - name: put machine back into rotation
    action: command echo inserting into rotation $inventory_hostname

Just replace the "command echo" with a call to the given script.

Of course, you could also write your own Ansible module to talk to any particular kind of load balancing device (rather than using a script), and you'll start to see more of these in the core of ansible in the future.

Say Thanks
Filed Under