How to get the hostname into jinja file

374 views
Skip to first unread message

Abdulrazzaq shaik

unread,
Jun 25, 2021, 6:04:08 AM6/25/21
to ansible...@googlegroups.com
Hi Folks,

Thank you for reading this.

My expectation is to get the hostname from the inventory file, please help how to get this.


Jinjafile :

teaserverurl: "http://{{tibcoteahost}}:8777/tea"


vars file :
tibco_tea_group"{{ groups['tibco_tea'] | default(ansible_play_hosts) | sort }}"
tibcoteahost>
   "{% for server in tibco_tea_group -%}
   {{ hostvars.get(server).ansible_all_ipv4_addresses }}
   {% endfor %}"

inventory file:
---
all:
  vars:
    ansible_connectionssh
    ansible_user: pibco
  children:
    tibco:
      vars:
        tibco_user: pibco
        tibco_group: pibgrp
        ansible_ssh_passMaddy1600
      hosts:
        tomlap01195.:
    tibco_tea:
      vars:
        tibco_user: pibco
        tibco_group: pibgrp
        ansible_ssh_passMaddy1600
      hosts:
        tomlap04090.corp:
    local:
      hosts:
        localhost:
          ansible_connectionlocal

Avinash Krishnan

unread,
Jun 26, 2021, 2:20:34 AM6/26/21
to Ansible Project
Hi,

Are you looking to set the url on each server during playbook execution ? You can use magic variable  inventory_hostname  to dynamically get hostname during play execution.

teaserverurl: "http://{{ inventory_hostname }}:8777/tea"


Reply all
Reply to author
Forward
0 new messages