postgresql_cluster
postgresql_cluster copied to clipboard
[Feat] When inventory_hostname is not an IP address it breaks deploy
Problem
In my case inventory_hostname ansible variable is set to a string that is not an actual IP-address of a host but looks like nonprod-db-10-9-12-189. It breaks all config templates, tls-cert-generates and other, where inventory_hostname is expected to be an actual IP-address.
Description
Instead of inventory_hostname in patroni, etcd and consul templates use another variable with a default value, which can be set up in inventory.
Importance
nice to have
Proposed implementation
No response
The presence of ip addresses in the inventory is currently a requirement.
The presence of ip addresses in the inventory is currently a requirement.
In my case an actual IP-address is in ansible_host variable
The presence of ip addresses in the inventory is currently a requirement.
I understand that etcd requires IP addresses for ETCD_LISTEN_* and ETCD_INITIAL_ADVERTISE_PEER_URLS, and that this is a limitation from etcd itself. So yes — using hostnames there will cause etcd to fail, and that behavior is expected.
However, the current implementation of the template in this role hardcodes inventory_hostname, which makes it impossible to use standard hostnames in the Ansible inventory without breaking etcd.
While defining IPs as inventory_hostname works as a workaround, it's not a clean or idiomatic solution in Ansible:
- It breaks readability and group logic (
hostvars,group_names, etc.). - It prevents the use of standard inventory naming practices.
A minimal and backward-compatible fix would be to use something like this in the template:
{{ etcd_bind_address | default(inventory_hostname) }}
This would allow users to override the bind address explicitly via a variable (e.g., etcd_bind_address: "{{ ansible_default_ipv4.address }}"), but would fall back to the current behavior otherwise — so there’s no impact on existing setups.
PR: https://github.com/vitabaks/autobase/pull/1089
I'd rather have different variables for consul, patroni, etcd and haproxy as well. It might be useful when, for some reason, consul listens on public interface, but patroni listens on private.
Done.