On Sun, 18 Aug 2024 15:11:11 +0100
Will McDonald <
wmcd...@gmail.com> 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