Ansible host variable access

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

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
   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
   command: /opt/splunk/bin/splunk add search-server {{ item }}:8089
     -auth {{ SPLUNK_UI_USERNAME }}:{{ Splunk_UI_Password }}
     -remoteUsername {{ SPLUNK_UI_USERNAME }}
     -remotePassword {{ Splunk_UI_Password }}
   with_items: "{{ groups['splunk-indexer'] }}"

Thanks for the help Mr Kai. I really appreciat :+1: