Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameters for patroni etcd username, password and namespace #473

Merged
merged 10 commits into from
Sep 26, 2023
10 changes: 9 additions & 1 deletion roles/confd/templates/confd.toml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ nodes = [
{% endif %}
{% if dcs_exists|bool and dcs_type == 'etcd' %}
{% for etcd_hosts in patroni_etcd_hosts %}
"http://{{etcd_hosts.host}}:{{etcd_hosts.port}}",
"{{ patroni_etcd_protocol | default('') or 'http' }}://{{etcd_hosts.host}}:{{etcd_hosts.port}}",
lavr marked this conversation as resolved.
Show resolved Hide resolved
{% endfor %}
{% endif %}
]
{% if dcs_exists|bool and dcs_type == 'etcd' %}
{% if patroni_etcd_username | default("") | length > 0 %}
username = "{{ patroni_etcd_username | default("") }}"
{% endif %}
{% if patroni_etcd_password | default("") | length > 0 %}
lavr marked this conversation as resolved.
Show resolved Hide resolved
password = "{{ patroni_etcd_password }}"
{% endif %}
{% endif %}
2 changes: 1 addition & 1 deletion roles/confd/templates/haproxy.toml.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[template]
prefix = "/service/{{ patroni_cluster_name }}"
prefix = "/{{ patroni_etcd_namespace | default("service") }}/{{ patroni_cluster_name }}"
lavr marked this conversation as resolved.
Show resolved Hide resolved
src = "haproxy.tmpl"
dest = "/etc/haproxy/haproxy.cfg"
{% if haproxy_installation_method == "src" %}
Expand Down
13 changes: 11 additions & 2 deletions roles/patroni/templates/patroni.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

scope: {{ patroni_cluster_name }}
name: {{ ansible_hostname }}
namespace: /service/
namespace: /{{ patroni_etcd_namespace | default("service") }}
lavr marked this conversation as resolved.
Show resolved Hide resolved

{% if patroni_log_destination == 'logfile' %}
log:
Expand Down Expand Up @@ -35,7 +35,16 @@ etcd3:
{% endif %}
{% if dcs_exists|bool and dcs_type == 'etcd' %}
etcd3:
hosts: {% for etcd_hosts in patroni_etcd_hosts %}{{etcd_hosts.host}}:{{etcd_hosts.port}}{% if not loop.last %},{% endif %}{% endfor %}
hosts: {% for etcd_hosts in patroni_etcd_hosts %}{{etcd_hosts.host}}:{{etcd_hosts.port}}{% if not loop.last %},{% endif %}{% endfor +%}
{% if patroni_etcd_username | default("") | length > 0 %}
username: {{ patroni_etcd_username | default("") }}
{% endif %}
{% if patroni_etcd_password | default("") | length > 0 %}
password: {{ patroni_etcd_password }}
{% endif %}
{% if patroni_etcd_protocol | default("") | length > 0 %}
lavr marked this conversation as resolved.
Show resolved Hide resolved
protocol: {{ patroni_etcd_protocol }}
{% endif %}
{% endif %}

{% if dcs_type == 'consul' %}
Expand Down
11 changes: 9 additions & 2 deletions roles/vip-manager/templates/vip-manager.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
interval: {{ vip_manager_interval }}

# the etcd or consul key which vip-manager will regularly poll.
trigger-key: "/service/{{ patroni_cluster_name }}/leader"
trigger-key: "/{{ patroni_etcd_namespace | default("service") }}/{{ patroni_cluster_name }}/leader"
lavr marked this conversation as resolved.
Show resolved Hide resolved
# if the value of the above key matches the trigger-value (often the hostname of this host), vip-manager will try to add the virtual ip address to the interface specified in Iface
trigger-value: "{{ ansible_hostname }}"

Expand All @@ -26,8 +26,15 @@ dcs-endpoints:
{% if dcs_exists|bool and dcs_type == 'etcd' %}
dcs-endpoints:
{% for etcd_hosts in patroni_etcd_hosts %}
- http://{{ etcd_hosts.host }}:{{ etcd_hosts.port }}
- {{ patroni_etcd_protocol | default('') or 'http' }}://{{ etcd_hosts.host }}:{{ etcd_hosts.port }}
lavr marked this conversation as resolved.
Show resolved Hide resolved
{% endfor %}

{% if patroni_etcd_username | default("") | length > 0 %}
etcd-user: {{ patroni_etcd_username | default("") }}
{% endif %}
{% if patroni_etcd_password | default("") | length > 0 %}
etcd-password: {{ patroni_etcd_password }}
{% endif %}
{% endif %}

# consul will always only use the first entry from this list.
Expand Down
4 changes: 4 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ patroni_etcd_hosts: [] # list of servers of an existing etcd cluster
# - { host: "10.128.64.140", port: "2379" }
# - { host: "10.128.64.142", port: "2379" }
# - { host: "10.128.64.143", port: "2379" }
patroni_etcd_namespace: "service" # (optional) etcd namespace (prefix)
patroni_etcd_username: "" # (optional) username for etcd authentication
patroni_etcd_password: "" # (optional) password for etcd authentication
patroni_etcd_protocol: "" # (optional) http or https, if not specified http is used

# more options you can specify in the roles/patroni/templates/patroni.yml.j2
# https://patroni.readthedocs.io/en/latest/SETTINGS.html#etcd
Expand Down