Last Updated: February 25, 2016
·
1.201K
· 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

  tasks:

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

# here's an alternate notation if you are delegating to 127.0.0.1, 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
    delegate_to: 127.0.0.1

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.