On 17.05.2019 07:15, James Armstrong wrote:
> 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 %}
--
Kai Stian Olstad
--
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/16b3eaca-6a3d-9014-4b0d-dafafe354c0a%40olstad.com.
For more options, visit https://groups.google.com/d/optout.