postgresql_cluster icon indicating copy to clipboard operation
postgresql_cluster copied to clipboard

[Feat] Allow setting descriptive host names instead of private ips

Open pat-s opened this issue 8 months ago • 1 comments

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.

pat-s avatar Mar 15 '25 16:03 pat-s

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.

vitabaks avatar Mar 17 '25 06:03 vitabaks

PR: https://github.com/vitabaks/autobase/pull/1089

vitabaks avatar Jun 27 '25 16:06 vitabaks

Done.

vitabaks avatar Jun 28 '25 18:06 vitabaks