# ansible 1.7.2 with multiline variables using the copy mod's 'content' directive

**URL:** <https://forum.ansible.com/t/ansible-1-7-2-with-multiline-variables-using-the-copy-mods-content-directive/16365>\
**Category:** Ansible Project\
**Created:** [September 27, 2014, 5:08pm UTC](https://forum.ansible.com/t/ansible-1-7-2-with-multiline-variables-using-the-copy-mods-content-directive/16365 "2014-09-27T17:08:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeffrey\_Wong](https://avatars.discourse-cdn.com/v4/letter/j/c37758/32.png) [@Jeffrey\_Wong](https://forum.ansible.com/u/Jeffrey_Wong)\
**Post date:** [September 27, 2014, 5:08pm UTC](https://forum.ansible.com/t/ansible-1-7-2-with-multiline-variables-using-the-copy-mods-content-directive/16365/1 "2014-09-27T17:08:42Z")

</div>

Hi there!

I noticed that ansible seemed to have done some updating with regards to multiline variables, and I’m a little confused about the way the variables are handled now.

My use case comes from inserting private-key data into an encrypted yaml file via ansible-vault, and printing the contents via copy module’s content directive. This worked great in 1.7.1, but with 1.7.2, it printed an extra newline between each line. Coincidentally, when I next deployed via ansible 1.7.2, my keys weren’t working.

The format is something like:

`group_vars/all.yml:`

`key: |+ -----BEGIN PRIVATE KEY---- (private key)`(private key)`  
`(private key)`  
-----END PRIVATE KEY-----

`

roles/tasks/main.yml:

`

- copy: content=“{{ key }}” dest=“/etc/ssl/private/key”

`

1.7.1 (correct):

` `-----BEGIN PRIVATE KEY----` `(private key)```(private key)`` ```(private key)````-----END PRIVATE KEY-----`

`

1.7.2 (incorrect):

` `-----BEGIN PRIVATE KEY----`

`(private key)`

`(private key)`

`(private key)`

`-----END PRIVATE KEY-----`

`

While looking through the github issues, there was a ticket that expressed exactly the issue I ran into:  
[https://github.com/ansible/ansible/issues/9172](https://github.com/ansible/ansible/issues/9172)

And it was resolved by following the ‘long’ format from:  
[https://github.com/ansible/ansible/issues/9067](https://github.com/ansible/ansible/issues/9067)

roles/tasks/main.yml (long format):

`

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 28, 2014, 7:29pm UTC](https://forum.ansible.com/t/ansible-1-7-2-with-multiline-variables-using-the-copy-mods-content-directive/16365/2 "2014-09-28T19:29:26Z")

</div>

Those changes are related to some security fixes and various related changes as a result of those fixes that came later, all aimed at preventing unexpected argument insertion given untrusted data from remote hosts.

So {{ foo }} is a request to insert something into a line, the way you have it above, and then ansible converts that into module arguments.

I have considered just undocumenting the “content” parameter – we’re likely to do that – as I think it leads to some confusing practices, better served by “template” in most cases.

One of those examples is pushing an embedded shell script inside a playbook, when it could have been done in a one-liner with the “script” module.

If you think you can fix it and still keep the argument detection/parsing in place, I’d be interested - but that’s why it was closed with the reasons given, and why I suggested how to avoid this.

The long form is also needed to pass structured data to modules, as is shown with the ec2 examples.

---

<div class="post-metadata">

**Author:** ![Jeffrey\_Wong](https://avatars.discourse-cdn.com/v4/letter/j/c37758/32.png) [@Jeffrey\_Wong](https://forum.ansible.com/u/Jeffrey_Wong)\
**Post date:** [September 29, 2014, 10:15pm UTC](https://forum.ansible.com/t/ansible-1-7-2-with-multiline-variables-using-the-copy-mods-content-directive/16365/3 "2014-09-29T22:15:27Z")

</div>

Thanks for the clarification!

I’ll go ahead and use a template instead if that’s what you’re recommending. It makes the most sense to deprecate/undocument content if it’s difficult to rectify strange differences with corner cases like that.

Thanks!

---

<div class="post-metadata">

**Author:** ![Alexandr\_Kurilin](https://avatars.discourse-cdn.com/v4/letter/a/8491ac/32.png) [@Alexandr\_Kurilin](https://forum.ansible.com/u/Alexandr_Kurilin)\
**Post date:** [October 5, 2014, 11:41pm UTC](https://forum.ansible.com/t/ansible-1-7-2-with-multiline-variables-using-the-copy-mods-content-directive/16365/4 "2014-10-05T23:41:04Z")

</div>

Assuming copy content goes away, is there any way to simplify the template module? Right now if I want to copy a PEM cert from the vault onto a target host, I have to create a set of files such as cert.j2 and key.j2 with contents {{ cert }} and {{ key }} respectively, so now I have to manage two additional files in my repo.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [October 6, 2014, 12:29pm UTC](https://forum.ansible.com/t/ansible-1-7-2-with-multiline-variables-using-the-copy-mods-content-directive/16365/5 "2014-10-06T12:29:04Z")

</div>

I’m not positive it’s going away, but you can use conditionals in a template, technically, if that helps you out.

---

<div class="post-metadata">

**Author:** ![Jacob\_Weber1](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Jacob\_Weber1](https://forum.ansible.com/u/Jacob_Weber1)\
**Post date:** [October 25, 2014, 5:27pm UTC](https://forum.ansible.com/t/ansible-1-7-2-with-multiline-variables-using-the-copy-mods-content-directive/16365/6 "2014-10-25T17:27:20Z")

</div>

Just ran into the same issue. I hope the “content” argument doesn’t go away; it’s very useful for simple things like SSH keys. But maybe you can document that using it with multi-line variables requires the long module syntax.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [October 25, 2014, 10:44pm UTC](https://forum.ansible.com/t/ansible-1-7-2-with-multiline-variables-using-the-copy-mods-content-directive/16365/7 "2014-10-25T22:44:45Z")

</div>

We’ve got a ticket open on this.

---

<div class="post-metadata">

**Author:** ![Jasper\_N\_Brouwer](https://avatars.discourse-cdn.com/v4/letter/j/d2c977/32.png) [@Jasper\_N\_Brouwer](https://forum.ansible.com/u/Jasper_N_Brouwer)\
**Post date:** [November 14, 2014, 10:41am UTC](https://forum.ansible.com/t/ansible-1-7-2-with-multiline-variables-using-the-copy-mods-content-directive/16365/8 "2014-11-14T10:41:07Z")

</div>

I ran into this issue as well. Changing “copy” to “template” works like a charm!

I just wanted to say I have no problems with this change, the extra templates needed (in a role) doesn’t bother me at all.
