Add ability to manage non-inventory hosts

We may want to load balance to existing services that we aren't managing
via ansible. Currently the hosts have to exist in the inventory in order
to add a VIP for these hosts, this patch adds the ability to set the
hostnames and addresses of the hosts manually when they aren't in the
ansible inventory.

Additionally, this patch adds a test for both the group method and the
host_lists method.

Change-Id: Ida66f401d8320d9bf14eac9b8014124631978808
(cherry picked from commit d2b2492c16)
This commit is contained in:
Andy McCrae 2017-12-14 13:49:38 +10:00 committed by Andy McCrae
parent 3e6d94eb86
commit edd3bf5e21
5 changed files with 59 additions and 4 deletions

View File

@ -170,6 +170,25 @@ An example HTTP service could look like:
haproxy_port: 10000
haproxy_balance_type: http
Additionally, you can specify haproxy services that are not managed
in the Ansible inventory by manually specifying their hostnames/IP Addresses:
.. code-block:: yaml
haproxy_extra_services:
- service:
haproxy_service_name: extra-non-inventory-service
haproxy_backend_nodes:
- name: nonInvHost01
ip_addr: 172.0.1.1
- name: nonInvHost02
ip_addr: 172.0.1.2
- name: nonInvHost03
ip_addr: 172.0.1.3
haproxy_ssl: "{{ haproxy_ssl }}"
haproxy_port: 10001
haproxy_balance_type: http
Adding additional global VIP addresses
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -0,0 +1,6 @@
---
features:
- HAProxy services that use backend nodes that are not
in the Ansible inventory can now be specified manually
by setting ``haproxy_backend_nodes`` to a list of
``name`` and ``ip_addr`` settings.

View File

@ -99,10 +99,13 @@ backend {{ item.service.haproxy_service_name }}-back
{% for host_name in item.service.haproxy_backend_nodes %}
{% if hostvars[host_name] is defined %}
{% set ip_addr = hostvars[host_name]['ansible_host'] %}
{% endif %}
{% set entry = [] %}
{% set _ = entry.append("server") %}
{% set _ = entry.append(host_name | string) %}
{% set _ = entry.append(hostvars[host_name]['ansible_host'] + ":" + haproxy_backend_port | string) %}
{% set _ = entry.append((host_name.name | default(host_name)) | string) %}
{% set _ = entry.append((host_name.ip_addr | default(ip_addr)) + ":" + haproxy_backend_port | string) %}
{% set _ = entry.append("check") %}
{% set _ = entry.append("port") %}
{% set _ = entry.append(haproxy_check_port | string) %}
@ -116,10 +119,13 @@ backend {{ item.service.haproxy_service_name }}-back
{% endfor %}
{% for host_name in item.service.haproxy_backup_nodes|default([]) %}
{% if hostvars[host_name] is defined %}
{% set ip_addr = hostvars[host_name]['ansible_host'] %}
{% endif %}
{% set entry = [] %}
{% set _ = entry.append("server") %}
{% set _ = entry.append(host_name | string) %}
{% set _ = entry.append(hostvars[host_name]['ansible_host'] + ":" + haproxy_backend_port | string) %}
{% set _ = entry.append((host_name.name | default(host_name)) | string) %}
{% set _ = entry.append((host_name.ip_addr | default(ip_addr)) + ":" + haproxy_backend_port | string) %}
{% set _ = entry.append("check") %}
{% set _ = entry.append("port") %}
{% set _ = entry.append(haproxy_check_port | string) %}

View File

@ -0,0 +1,2 @@
---
ansible_host: 127.0.0.1

View File

@ -1,2 +1,24 @@
---
external_lb_vip_address: 127.0.0.1
internal_lb_vip_address: 127.0.0.1
haproxy_service_configs:
- service:
haproxy_service_name: test_group
haproxy_backend_nodes: "{{ groups['haproxy_all'] | default([]) }}"
haproxy_port: 8180
haproxy_backend_port: 22
haproxy_ssl: False
haproxy_balance_type: tcp
haproxy_backend_options:
- tcp-check
- service:
haproxy_service_name: test_list
haproxy_backend_nodes:
- name: "localhost"
ip_addr: "127.0.0.1"
haproxy_port: 8181
haproxy_backend_port: 22
haproxy_ssl: False
haproxy_balance_type: tcp
haproxy_backend_options:
- tcp-check