diff --git a/doc/source/configure-haproxy.rst b/doc/source/configure-haproxy.rst index dce5248..3b2aa21 100644 --- a/doc/source/configure-haproxy.rst +++ b/doc/source/configure-haproxy.rst @@ -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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/releasenotes/notes/non_inventory_hosts-c0fa4c185a01e78b.yaml b/releasenotes/notes/non_inventory_hosts-c0fa4c185a01e78b.yaml new file mode 100644 index 0000000..43a6c48 --- /dev/null +++ b/releasenotes/notes/non_inventory_hosts-c0fa4c185a01e78b.yaml @@ -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. diff --git a/templates/service.j2 b/templates/service.j2 index 773f356..243a635 100644 --- a/templates/service.j2 +++ b/templates/service.j2 @@ -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) %} diff --git a/tests/host_vars/localhost.yml b/tests/host_vars/localhost.yml new file mode 100644 index 0000000..39e5c64 --- /dev/null +++ b/tests/host_vars/localhost.yml @@ -0,0 +1,2 @@ +--- +ansible_host: 127.0.0.1 diff --git a/tests/test-vars.yml b/tests/test-vars.yml index 0274176..e22fb46 100644 --- a/tests/test-vars.yml +++ b/tests/test-vars.yml @@ -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