Generating a single line comma separated string variable from host group

Hey,

I’ve been pulling my hair out over what seems like a relatively simple task for hours now.

I’ve working on playbook for an Elasticsearch deployment. One requirement for this is a config file item that is effectively just a comma separated list of hostnames or IP’s of nodes.

e.g.

discovery.zen.ping.unicast.hosts: [“hostname1”, “hostname2”, “hostname3”]

Functionally at this point I would want to generate an output here that would effective append the bellow registered variable:

node_masters: [" “{{ansible_hostname (FIRST GROUP MEMBER) }}”, “{{ansible_hostname (SECOND GROUP MEMBER) }}”, “{{ansible_hostname (THIRD GROUP MEMBER) }}”

The current j2 template for the config file uses a to_nice_yaml filter for the es_config variable

{% if es_config %}
{{ es_config | to_nice_yaml }}
{% endif %}

I just want to get to a point where i can basically just feed in my theorical node_masters var to the es_config part of the play like bellow:

es_config:
network.host: “{{ ansible_fqdn }}”
cluster.name: “lab-cluster”
discovery.zen.ping.unicast.hosts: {{ node_masters }}
discovery.zen.minimum_master_nodes: 1
http.port: 9200
node.data: true
node.master: true
bootstrap.memory_lock: false

Hey,

I've been pulling my hair out over what seems like a relatively simple task
for hours now.

I've working on playbook for an Elasticsearch deployment. One requirement
for this is a config file item that is effectively just a comma separated
list of hostnames or IP's of nodes.

e.g.

discovery.zen.ping.unicast.hosts: ["hostname1", "hostname2", "hostname3"]

The value here is more a json syntax that a yaml syntax, at least when it comes to to_nice_yaml you are using bellow.

Functionally at this point I would want to generate an output here that
would effective append the bellow registered variable:

node_masters: [" "{{ansible_hostname (FIRST GROUP MEMBER) }}",
"{{ansible_hostname (SECOND GROUP MEMBER) }}", "{{ansible_hostname (THIRD
GROUP MEMBER) }}"

The current j2 template for the config file uses a to_nice_yaml filter for
the es_config variable

{% if es_config %}
{{ es_config | to_nice_yaml }}
{% endif %}

I just want to get to a point where i can basically just feed in my
theorical node_masters var to the es_config part of the play like bellow:

es_config:
       network.host: "{{ ansible_fqdn }}"
       cluster.name: "lab-cluster"
       *discovery.zen.ping.unicast.hosts: {{ node_masters }}*
       discovery.zen.minimum_master_nodes: 1
       http.port: 9200
       node.data: true
       node.master: true
       bootstrap.memory_lock: false

The easiest is probably to make es_config string with yaml multi-line(pay attention to the pipe) instead of a dict.

es_config: |
  network.host: {{ ansible_fqdn }}
  cluster.name: lab-cluster
  discovery.zen.ping.unicast.hosts: {{ node_masters | to_json }}
  discovery.zen.minimum_master_nodes: 1
  http.port: 9200
  node.data: true
  node.master: true
  bootstrap.memory_lock: false

And the in the template so this

{% if es_config %}
{{ es_config }}
{% endif %}