On Sun, 18 Aug 2024 15:11:11 +0100
Will McDonald <[email protected]> wrote:

> There may be more elegant ways to achieve this

The below declaration should to the job

    seeds: "{{ ansible_play_hosts |
               difference([inventory_hostname]) |
               map('extract', hostvars, 'ansible_host') |
               product([':2113']) |
               map('join') |
               join(',') }}"

> {%- set seeds = [] %}
> {%- for host in ansible_play_hosts %}
>   {%- if host != inventory_hostname %}
>     {{ seeds.append(hostvars[host]['ansible_host'] ~ ':2113') }}
>   {%- endif %}
> {%- endfor %}
> 
> GossipSeed: {{ seeds | join(',') }}

For example, given the inventory


  shell> cat hosts
  host_A ansible_host=10.1.0.51
  host_B ansible_host=10.1.0.52
  host_C ansible_host=10.1.0.53

the below play

  - hosts: all
    vars:
      seeds: "{{ ansible_play_hosts |
                 difference([inventory_hostname]) |
                 map('extract', hostvars, 'ansible_host') |
                 product([':2113']) |
                 map('join') |
                 join(',') }}"
    tasks:
      - debug:
          var: seeds

gives (abridged)

ok: [host_A] => 
  seeds: 10.1.0.53:2113,10.1.0.52:2113
ok: [host_B] => 
  seeds: 10.1.0.53:2113,10.1.0.51:2113
ok: [host_C] => 
  seeds: 10.1.0.51:2113,10.1.0.52:2113

HTH,

-- 
Vladimir Botka

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20240818180500.6cbdd318%40gmail.com.

Attachment: pgpKnie3teTXh.pgp
Description: OpenPGP digital signature

Reply via email to