How to join domain name to a list of short hostname

Viewed 52

I have list of short hostnames and string of domain name

How can I join these together?

dns_domain: 'local.out'
short_nodes: [ name1, name2, name3 ]

and I want

[ name1.local.out, name2.local.out, name3.local.out ]

I tried

set_facts:
  nodes: "{{ short_nodes | default([]) + ['.'.join( {{ dns_domain }}) }}

but, that gives me error.

1 Answers

You will need a product to map your domain name to each nodes.
Then, it is easy to join the lists of list created with map.

Given the task:

- debug:
    var: short_nodes  | product([dns_domain])  |  map('join', '.')
  vars:
    dns_domain: local.out
    short_nodes:
      - name1
      - name2
      - name3 

This yields

ok: [localhost] => 
  short_nodes  | product([dns_domain])  |  map('join', '.'):
  - name1.local.out
  - name2.local.out
  - name3.local.out
Related