# Quick question about transforming variables for templates

**URL:** <https://forum.ansible.com/t/quick-question-about-transforming-variables-for-templates/12681>\
**Category:** Ansible Project\
**Created:** [April 14, 2013, 8:11am UTC](https://forum.ansible.com/t/quick-question-about-transforming-variables-for-templates/12681 "2013-04-14T08:11:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yang\_Zhang](https://avatars.discourse-cdn.com/v4/letter/y/96bed5/32.png) [@Yang\_Zhang](https://forum.ansible.com/u/Yang_Zhang)\
**Post date:** [April 14, 2013, 8:11am UTC](https://forum.ansible.com/t/quick-question-about-transforming-variables-for-templates/12681/1 "2013-04-14T08:11:53Z")

</div>

Probably just missed something basic in the docs, but for each host  
foo.internal.company.com, I'd like to create a /etc/ddclient.conf file  
containing the string "foo." What's the best way to do this? I'm  
thinking templates, but not sure how to get just the first component  
of inventory\_hostname. Should I be defining filter plugins for this?  
(The note on filter plugins in the docs was pretty brief - is there a  
place in my project I can define filter plugins?) Thanks.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [April 14, 2013, 12:57pm UTC](https://forum.ansible.com/t/quick-question-about-transforming-variables-for-templates/12681/2 "2013-04-14T12:57:53Z")

</div>

{{ inventory\_hostname\_short }} is already available for this purpose for the current host you are operating on, but if you need to list more than one host or use this trick for other variables, you can do things like:

{{ variable.split(“.”)[0] }}
