Skip to content

Conversation

@pavlozt
Copy link

@pavlozt pavlozt commented Nov 30, 2025

This change allows you to specify external IPs when they are not available from ansible facts.
Here's an example playbook:
variable hostname_fqdn must be defined in inventory

#!/usr/bin/env ansible-playbook
- name: Prepare app
  become: true
  hosts: etcd
  vars:
    etcd_ca_conf_directory: ./certs/
    etcd_ansible_group: "etcd"
    etcd_interface: eth0
    etcd_peer_port: "2380"
    etcd_client_port: "2379"
    initial_cluster_value: >-
      {% for host in groups[etcd_ansible_group] -%}
      {{ hostvars[host]['ansible_hostname'] }}=https://{{ hostvars[host]['hostname_fqdn'] }}:2380
      {%- if not loop.last %},{% else %}{% endif %}{%- endfor %}
  pre_tasks:
    - name: Set etcd_settings_user facts
      set_fact:
        etcd_settings_user:
          initial-advertise-peer-urls: "https://{{ hostvars[inventory_hostname]['hostname_fqdn'] }}:{{ etcd_peer_port }}"
          advertise-client-urls: "https://{{ hostvars[inventory_hostname]['hostname_fqdn'] }}:{{ etcd_client_port }}"
          initial-cluster: "{{ initial_cluster_value | trim }}"

    - name: Show debug info
      debug:
        var: etcd_settings_user
  roles:
    - githubixx.etcd

A practical case is if you run Etcd in the Internet or with multiple cloud providers

@pavlozt pavlozt requested a review from githubixx December 6, 2025 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants