# Multiline template replacing

**URL:** <https://forum.ansible.com/t/multiline-template-replacing/13312>\
**Category:** Ansible Project\
**Created:** [August 15, 2013, 9:19am UTC](https://forum.ansible.com/t/multiline-template-replacing/13312 "2013-08-15T09:19:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![howachen](https://avatars.discourse-cdn.com/v4/letter/h/54ee81/32.png) [@howachen](https://forum.ansible.com/u/howachen)\
**Post date:** [August 15, 2013, 9:19am UTC](https://forum.ansible.com/t/multiline-template-replacing/13312/1 "2013-08-15T09:19:29Z")

</div>

Not sure why I can’t reply to this thread: [https://groups.google.com/forum/#!topic/ansible-project/EDXIk3WM7vk](https://groups.google.com/forum/#!topic/ansible-project/EDXIk3WM7vk)

But here is the question:

As suggested by Micheal, I can use the following if I want to use mutliline

---

<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:** [August 15, 2013, 12:32pm UTC](https://forum.ansible.com/t/multiline-template-replacing/13312/2 "2013-08-15T12:32:13Z")

</div>

“It fails” is not the best way to report a problem. You should show /how/ you percieved the failure so we can understand what you are talking about.

You are indenting the “copy” line weird for sure, and i have no idea if you have “dest” defined appropriately.

---

<div class="post-metadata">

**Author:** ![Kavin\_Kankeshwar](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@Kavin\_Kankeshwar](https://forum.ansible.com/u/Kavin_Kankeshwar)\
**Post date:** [August 15, 2013, 1:52pm UTC](https://forum.ansible.com/t/multiline-template-replacing/13312/3 "2013-08-15T13:52:35Z")

</div>

I have had not so good luck with using {{ var }} in playbooks. I still use ${var}, which works fine.

e.g.

This works

---

<div class="post-metadata">

**Author:** ![benno\_joy](https://avatars.discourse-cdn.com/v4/letter/b/73ab20/32.png) [@benno\_joy](https://forum.ansible.com/u/benno_joy)\
**Post date:** [August 15, 2013, 2:04pm UTC](https://forum.ansible.com/t/multiline-template-replacing/13312/4 "2013-08-15T14:04:31Z")

</div>

Hi Kavin

that would be - hosts: “{{ hosts }}”  
so if the variable is the first value of a yaml key it should be quoted, with an exception of “when”

- Benno

---

<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:** [August 15, 2013, 2:15pm UTC](https://forum.ansible.com/t/multiline-template-replacing/13312/5 "2013-08-15T14:15:25Z")

</div>

This is because when starting a line with { YAML needs the line quoted since it thinks you want a hash

{{ foo }}

works fine, you just have to know that.

You should also be able tell because the error you get is about YAML syntax, it’s not saying something about Ansible

---

<div class="post-metadata">

**Author:** ![Kavin\_Kankeshwar](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@Kavin\_Kankeshwar](https://forum.ansible.com/u/Kavin_Kankeshwar)\
**Post date:** [August 15, 2013, 4:15pm UTC](https://forum.ansible.com/t/multiline-template-replacing/13312/6 "2013-08-15T16:15:03Z")

</div>

Thank you very much!!!

🙂 I should visit the documentation site more often. Found this in [Gotchas](http://www.ansibleworks.com/docs/YAMLSyntax.html#gotchas)

---

<div class="post-metadata">

**Author:** ![howachen](https://avatars.discourse-cdn.com/v4/letter/h/54ee81/32.png) [@howachen](https://forum.ansible.com/u/howachen)\
**Post date:** [August 16, 2013, 4:22pm UTC](https://forum.ansible.com/t/multiline-template-replacing/13312/7 "2013-08-16T16:22:44Z")

</div>

Hi

It failed I mean the {{ xxx }} didn’t get replaced during template execution when I am using multi-line method, it just leave as the original string as it.

The copy & dest alignment is just as an example, if I use a non {{ xxx }}, it works and get replaced.
