# Replace host name in yml file

**URL:** <https://forum.ansible.com/t/replace-host-name-in-yml-file/22267>\
**Category:** Ansible Project\
**Created:** [August 10, 2016, 5:43pm UTC](https://forum.ansible.com/t/replace-host-name-in-yml-file/22267 "2016-08-10T17:43:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anushri\_Mishra](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@Anushri\_Mishra](https://forum.ansible.com/u/Anushri_Mishra)\
**Post date:** [August 10, 2016, 5:43pm UTC](https://forum.ansible.com/t/replace-host-name-in-yml-file/22267/1 "2016-08-10T17:43:59Z")

</div>

hi I have a question this is my main.yml file content:

- name: Start Tomcat

# service: name=tomcat7 state=restarted enabled=yes

command: wget “[http://admin](http://admin):admin@ **10.1.33.155** :8080/manager/text/stop?path=/externaluserwebapi” -O - -q

become: True

become\_method: sudo

run\_once: true

changed\_when: False

Now as you can see there is server name in the command itself (bolded) and it is basically stopping a given application running in tomcat server vs the whole server.

Now my problem is that how can i run this for the given hosts file. Is there a way I can replace the hardcoded server name here by hosts from the hosts file?

Please advise.

Thanks.

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [August 10, 2016, 6:40pm UTC](https://forum.ansible.com/t/replace-host-name-in-yml-file/22267/2 "2016-08-10T18:40:47Z")

</div>

That command is going to run on the tomcat server, so you probably can  
just use 127.0.0.1

---

<div class="post-metadata">

**Author:** ![Anushri\_Mishra](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@Anushri\_Mishra](https://forum.ansible.com/u/Anushri_Mishra)\
**Post date:** [August 10, 2016, 6:51pm UTC](https://forum.ansible.com/t/replace-host-name-in-yml-file/22267/3 "2016-08-10T18:51:53Z")

</div>

omg never thought of that 🙂 thanks !!
