postgresql_cluster
postgresql_cluster copied to clipboard
[Feat] Allow setting descriptive host names instead of private ips
Problem
Currently, etcd_cluster and others expect a (private) IP as their host name in the ansible inventory as this information is used within the playbooks.
Description
An alternative would be to query the local addresses dynamically within the playbook and allow setting descriptive host names instead. This would align more closely to the classical Ansible approach.
Importance
nice to have
Proposed implementation
Proof of concept:
- name: Debug
hosts: etcd_cluster
become: true
gather_facts: true
tasks:
- name: Extract private IP
set_fact:
internal_ip: "{{ ansible_all_ipv4_addresses | ipaddr('private') | first | default('No internal IP found') }}"
- name: Show the internal IP
debug:
msg: 'Internal IP Address: {{ internal_ip }}'
TASK [Show the internal IP] **************************************************************************************************************************************************
ok: [10.10.1.1] => {
"msg": "Internal IP Address: 10.10.1.1"
}
ok: [10.10.1.2] => {
"msg": "Internal IP Address: 10.10.1.2"
}
ok: [10.10.1.3] => {
"msg": "Internal IP Address: 10.10.1.3"
}
In this case, the variable internal_ip could be used within the playbooks.
This logic would need to account for edge cases, e.g. when multiple private interfaces are available. In this case, an optional list variable could be added in which the respective interfaces per node can be set.
I think it’s time for us to support this feature, as there have already been several requests to remove the requirement of specifying a private IP in inventory_hostname.
Please also take a look at this PR here, where a similar implementation was attempted.
Additionally, it’s important to maintain backward compatibility with the current approach, as it is used by the Autobase Console when generating the inventory JSON.
PR: https://github.com/vitabaks/autobase/pull/1089
Done.