# Based on hostname select variables.

**URL:** <https://forum.ansible.com/t/based-on-hostname-select-variables/18562>\
**Category:** Ansible Project\
**Created:** [June 22, 2015, 6:12am UTC](https://forum.ansible.com/t/based-on-hostname-select-variables/18562 "2015-06-22T06:12:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dhanasekaran\_Anbalag](https://avatars.discourse-cdn.com/v4/letter/d/f6c823/32.png) [@Dhanasekaran\_Anbalag](https://forum.ansible.com/u/Dhanasekaran_Anbalag)\
**Post date:** [June 22, 2015, 6:12am UTC](https://forum.ansible.com/t/based-on-hostname-select-variables/18562/1 "2015-06-22T06:12:10Z")

</div>

Hi Guys,

I am new to ansible world, Based on hostname I need to select variables and feed input to template file.

In my case :: I need to deploy app on multiple hosts, based on hostname I need to configure db\_name and db\_user and db\_pass etc…

Please guide me, How to do this.

-Dhanasekaran.

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [June 22, 2015, 12:45pm UTC](https://forum.ansible.com/t/based-on-hostname-select-variables/18562/2 "2015-06-22T12:45:35Z")

</div>

There probably several ways of doing this.

To start with have a look at ‘host\_vars’ - you can set variables for each machine in your inventory: [http://docs.ansible.com/intro\_inventory.html#host-variables](http://docs.ansible.com/intro_inventory.html#host-variables)

You will probably find very soon after that you want to set the same variables for groups of servers, so read about group vars as well (on the same page).

Hope this helps,

Jon
