# Write template from a string input

**URL:** <https://forum.ansible.com/t/write-template-from-a-string-input/17487>\
**Category:** Ansible Project\
**Created:** [February 10, 2015, 11:21am UTC](https://forum.ansible.com/t/write-template-from-a-string-input/17487 "2015-02-10T11:21:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Stucki](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@Michael\_Stucki](https://forum.ansible.com/u/Michael_Stucki)\
**Post date:** [February 10, 2015, 11:21am UTC](https://forum.ansible.com/t/write-template-from-a-string-input/17487/1 "2015-02-10T11:21:50Z")

</div>

Hi!

I’m trying to write a file. As it’s only one line, I would like to set it from a string input, not from a template file. Just something like:

- template: \>  
dest=/etc/default/locale  
content=‘LC\_ALL=“en\_US.UTF-8”’

As far as I can see, there is no such thing right now.

I’m working around that using the lineinfile module, but this is really cumbersome for such a purpose:

- lineinfile: \>  
dest=/etc/default/locale  
line=‘LC\_ALL=“de\_C2.UTF-8”’  
regexp=‘^’

I also think that the lineinfile module is not meant for this, but I also didn’t find any other way. Does anyone know?

Greetings, Michael

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 10, 2015, 12:24pm UTC](https://forum.ansible.com/t/write-template-from-a-string-input/17487/2 "2015-02-10T12:24:02Z")

</div>

I think you want the following:

- copy: \>  
&nbsp;&nbsp;&nbsp;&nbsp;dest=/etc/default/locale  
&nbsp;&nbsp;&nbsp;&nbsp;content='LC\_ALL="en\_US.UTF-8"'

---

<div class="post-metadata">

**Author:** ![Tom\_Bamford](https://avatars.discourse-cdn.com/v4/letter/t/c2a13f/32.png) [@Tom\_Bamford](https://forum.ansible.com/u/Tom_Bamford)\
**Post date:** [February 10, 2015, 12:27pm UTC](https://forum.ansible.com/t/write-template-from-a-string-input/17487/3 "2015-02-10T12:27:01Z")

</div>

Hi Michael

The copy module does have a content parameter that should do what you want.

Regards  
Tom

---

<div class="post-metadata">

**Author:** ![Michael\_Stucki](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@Michael\_Stucki](https://forum.ansible.com/u/Michael_Stucki)\
**Post date:** [February 10, 2015, 1:27pm UTC](https://forum.ansible.com/t/write-template-from-a-string-input/17487/4 "2015-02-10T13:27:33Z")

</div>

Many thanks, this works!

Michael
