using hosts mentioned in inventory files in my tasks

15 views
Skip to first unread message

Vishal Bobade

unread,
Feb 26, 2020, 6:19:11 AM2/26/20
to Ansible Project
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

<inventory file>

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


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

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"

shell script :

---------------------------------------------->
read -p "Enter a server name for Sonarqube : " SQ 
if [ -z "$SQ" ]; then 
 echo "DNS name for sonarqube not provided, cannot proceed" 
 exit 1 
else 
 sed -i s/sonarqube.dummy.domain.net/$SQ/g  /opt/sonarqube/*.json 
fi
<---------------------------------------------

Srinivas Naram

unread,
Feb 27, 2020, 2:22:23 AM2/27/20
to ansible...@googlegroups.com
try {{ inventory_hostname }}

Regards
Srini

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/915a168d-4b8f-4437-80e9-f45cf3af9d35%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages