# Ansible host variable access

**URL:** <https://forum.ansible.com/t/ansible-host-variable-access/25436>\
**Category:** Ansible Project\
**Created:** [September 8, 2017, 3:59am UTC](https://forum.ansible.com/t/ansible-host-variable-access/25436 "2017-09-08T03:59:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![parwinderjit\_singh](https://avatars.discourse-cdn.com/v4/letter/p/eb8c5e/32.png) [@parwinderjit\_singh](https://forum.ansible.com/u/parwinderjit_singh)\
**Post date:** [September 8, 2017, 3:59am UTC](https://forum.ansible.com/t/ansible-host-variable-access/25436/1 "2017-09-08T03:59:24Z")

</div>

Hi,

Need some help

My host file is

[splunk-head]  
parv-vm-01 ansible\_ssh\_host=10.48.21.99 host\_fqdn=parv-vm-01

[splunk-indexer]  
parv-vm-02 ansible\_ssh\_host=10.48.21.94 host\_fqdn1=parv-vm-02  
parv-vm-03 ansible\_ssh\_host=10.48.21.96 host\_fqdn=parv-vm-03  
parv-vm-04 ansible\_ssh\_host=10.48.21.86 host\_fqdn=parv-vm-04

[splunk-Forwarder]  
parv-vm-05 ansible\_ssh\_host=10.48.21.87 host\_fqdn=parv-vm-05  
parv-vm-06 ansible\_ssh\_host=10.48.21.85 host\_fqdn=parv-vm-06  
parv-vm-07 ansible\_ssh\_host=10.48.21.84 host\_fqdn=parv-vm-07  
parv-vm-08 ansible\_ssh\_host=10.48.21.107 host\_fqdn=parv-vm-08  
parv-vm-09 ansible\_ssh\_host=10.48.21.109 host\_fqdn=parv-vm-09

I am installing search-head of splunk on one server but i need to run one command which need all hostname of splunk-indexer

- name: add search-indexer  
command: /opt/splunk/bin/splunk add search-server \<hostname of splunk-indexer 1\>:8089 -auth {{ SPLUNK\_UI\_USERNAME }}:{{ Splunk\_UI\_Password }} -remoteUsername {{ SPLUNK\_UI\_USERNAME }} -remotePassword {{ Splunk\_UI\_Password }}

i need to run above command three times so that the command will run three times and add 10.48.21.94, 10.48.21.96, 10.48.21.86

Can anyone help me

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [September 8, 2017, 6:08am UTC](https://forum.ansible.com/t/ansible-host-variable-access/25436/2 "2017-09-08T06:08:48Z")

</div>

> My host file is
> 
> [splunk-head]  
> parv-vm-01 ansible\_ssh\_host=10.48.21.99 host\_fqdn=parv-vm-01
> 
> [splunk-indexer]  
> parv-vm-02 ansible\_ssh\_host=10.48.21.94 host\_fqdn1=parv-vm-02  
> parv-vm-03 ansible\_ssh\_host=10.48.21.96 host\_fqdn=parv-vm-03  
> parv-vm-04 ansible\_ssh\_host=10.48.21.86 host\_fqdn=parv-vm-04

\<snip /\>

> I am installing search-head of splunk on one server but i need to run one  
> command which need all hostname of splunk-indexer
> 
> - name: add search-indexer  
> &nbsp;&nbsp;&nbsp;command: /opt/splunk/bin/splunk add search-server \<hostname of  
> splunk-indexer 1\>:8089 -auth {{ SPLUNK\_UI\_USERNAME }}:{{ Splunk\_UI\_Password  
> }} -remoteUsername {{ SPLUNK\_UI\_USERNAME }} -remotePassword {{  
> Splunk\_UI\_Password }}
> 
> i need to run above command three times so that the command will run three  
> times and add 10.48.21.94, 10.48.21.96, 10.48.21.86

- name: add search-indexer  
&nbsp;&nbsp;&nbsp;command: /opt/splunk/bin/splunk add search-server {{ item }}:8089  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-auth {{ SPLUNK\_UI\_USERNAME }}:{{ Splunk\_UI\_Password }}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-remoteUsername {{ SPLUNK\_UI\_USERNAME }}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-remotePassword {{ Splunk\_UI\_Password }}  
&nbsp;&nbsp;&nbsp;with\_items: "{{ groups['splunk-indexer'] }}"

---

<div class="post-metadata">

**Author:** ![parwinderjit\_singh](https://avatars.discourse-cdn.com/v4/letter/p/eb8c5e/32.png) [@parwinderjit\_singh](https://forum.ansible.com/u/parwinderjit_singh)\
**Post date:** [September 8, 2017, 6:27am UTC](https://forum.ansible.com/t/ansible-host-variable-access/25436/3 "2017-09-08T06:27:53Z")

</div>

Thanks for the help Mr Kai. I really appreciat 👍
