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
This commit is contained in:
parent
9966fd96fe
commit
d2b2492c16
@ -167,6 +167,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
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -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.
|
@ -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) %}
|
||||
|
2
tests/host_vars/localhost.yml
Normal file
2
tests/host_vars/localhost.yml
Normal file
@ -0,0 +1,2 @@
|
||||
---
|
||||
ansible_host: 127.0.0.1
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user