ansible with elastic search with Jinja2 Template

19 views
Skip to first unread message

Bishwajit Samanta

unread,
Apr 13, 2018, 10:51:31 AM4/13/18
to Ansible Project


Hi, my question is :: 
--------------------------------

My ansible script will be running for multiple systems. But in elasticsearch.jinja2 how can i change the value of node.name for different systems.

Jinja 2 Code::-
-------------------

# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
 cluster.name: {{ my_defined_cluster_name }}
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
 node.name: {{ my_defined_node_name }}
#
# Add custom attributes to the node:
#
# node.rack: r1

If i am running this jinja2 file, across all the systems the value of node.name will be same. But i dont want this, i want to put some other values when it runs to other systems. 

what modification i can do in Jinja2 file , can anyone help me ??

My ansible playbook looks like this::


---

## Task Related to Configuration of Elastic Search :: 

- name: Copy Configuration file for Elastic Search 
  template:
    src: elasticsearch.jinja2
    dest: /etc/elasticsearch/elasticsearch.yml
    mode: 0750
    owner: root
    group: elasticsearch


Bishwajit Samanta

unread,
Apr 13, 2018, 1:56:57 PM4/13/18
to Ansible Project
Can anyone help me in my problem please ? 

Larry Smith

unread,
Apr 14, 2018, 12:55:50 AM4/14/18
to Ansible Project
You can use:
node.name: {{ansible_hostname}}

Which will use the hostname defined on the remote host.

Or you can use:
node.name:{{inventory_hostname}}

Which will use the inventory hostname defined in your Ansible inventory.

For reference:

Bishwajit Samanta

unread,
Apr 14, 2018, 1:10:21 AM4/14/18
to Ansible Project
Thanks Larry for such great help.. i hope this solves my problem. !! :) 
Reply all
Reply to author
Forward
0 new messages