# using hosts mentioned in inventory files in my tasks

**URL:** <https://forum.ansible.com/t/using-hosts-mentioned-in-inventory-files-in-my-tasks/32332>\
**Category:** Ansible Project\
**Created:** [February 26, 2020, 11:19am UTC](https://forum.ansible.com/t/using-hosts-mentioned-in-inventory-files-in-my-tasks/32332 "2020-02-26T11:19:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vishal\_Bobade](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@Vishal\_Bobade](https://forum.ansible.com/u/Vishal_Bobade)\
**Post date:** [February 26, 2020, 11:19am UTC](https://forum.ansible.com/t/using-hosts-mentioned-in-inventory-files-in-my-tasks/32332/1 "2020-02-26T11:19:11Z")

</div>

Hello ,

I have a inventory file with some 5-6 hosts and I want use them in some of my tasks/main.yml file. Could some one please suggest how can I do that .

Lets say below is my inventory file

```auto
[gameday]
grafana.domain.net
gitlab.domain.net
sonarqube.domain.net
artifactory.domain.net
prometheus.domain.net

```

```auto

```

```auto

```

```auto
I want to use them in some shell script which is going to be run as a part of some tasks.

```

```auto

```

```auto
for example below is some script where I want to replace "sonarqube.dummy.domain.net" this with the one in inventory file which is "sonarqube.domain.net"

```

```auto

```

```auto

```

```auto
**shell script :**

```

```auto

```

```auto
---------------------------------------------->

```

```auto
read -p "Enter a server name for Sonarqube : " SQ 

```

```auto
if [-z "$SQ"]; then 

```

```auto
 echo "DNS name for sonarqube not provided, cannot proceed" 

```

```auto
 exit 1 

```

```auto
else 

```

```auto
 sed -i s/sonarqube.dummy.domain.net/$SQ/g /opt/sonarqube/*.json 

```

```auto
fi

```

```auto
<---------------------------------------------

```

---

<div class="post-metadata">

**Author:** ![Srinivas\_Naram](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@Srinivas\_Naram](https://forum.ansible.com/u/Srinivas_Naram)\
**Post date:** [February 27, 2020, 7:21am UTC](https://forum.ansible.com/t/using-hosts-mentioned-in-inventory-files-in-my-tasks/32332/2 "2020-02-27T07:21:49Z")

</div>

try {{ inventory\_hostname }}

Regards  
Srini
