# How to split action into multiline?

**URL:** <https://forum.ansible.com/t/how-to-split-action-into-multiline/13270>\
**Category:** Ansible Project\
**Created:** [August 7, 2013, 5:07pm UTC](https://forum.ansible.com/t/how-to-split-action-into-multiline/13270 "2013-08-07T17:07:24Z")\
**Posts on this page:** 9\
**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 7, 2013, 5:07pm UTC](https://forum.ansible.com/t/how-to-split-action-into-multiline/13270/1 "2013-08-07T17:07:24Z")

</div>

How to split action into multiline?

e.g.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [August 7, 2013, 6:12pm UTC](https://forum.ansible.com/t/how-to-split-action-into-multiline/13270/2 "2013-08-07T18:12:23Z")

</div>

Your indentation is off.

Several options.

# (1) complex arguments by passing a hash to the module

&nbsp;&nbsp;- name: Update the Apache config  
&nbsp;&nbsp;&nbsp;&nbsp;copy:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src: httpd.conf  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: /etc/httpd/httpd.conf

# (2) or equivalently

&nbsp;&nbsp;- name: Update the Apache config  
&nbsp;&nbsp;&nbsp;&nbsp;action:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;module: copy  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src: httpd.conf  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: /etc/httpd/httpd.conf

# (3) YAML line continuations

&nbsp;&nbsp;- name: Update the Apache config  
&nbsp;&nbsp;&nbsp;&nbsp;copy: \>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src=httpd.conf  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest=/etc/httpd/httpd.conf

# )4\_ YAML line continuations

&nbsp;&nbsp;- name: Update the Apache config  
&nbsp;&nbsp;&nbsp;&nbsp;action: copy \>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src=httpd.conf  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest=/etc/httpd/httpd.conf

I generally prefer option 1 or 3.

---

<div class="post-metadata">

**Author:** ![Andy1](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@Andy1](https://forum.ansible.com/u/Andy1)\
**Post date:** [August 7, 2013, 8:01pm UTC](https://forum.ansible.com/t/how-to-split-action-into-multiline/13270/3 "2013-08-07T20:01:05Z")

</div>

I usually prefer 1 too, since the others get messy quickly and it creates better diff in git. But it makes problems with modules which don’t have a named argument. For instance:

- name: Create SSH keypair files  
command: \>  
ssh-keygen -f id\_rsa -N ‘’  
creates=id\_rsa

work but I cannot do:

- name: Create SSH keypair files  
command:  
command: ssh-keygen -f id\_rsa -N ‘’  
creates: id\_rsa

Is there a way? I also tried to “0:” instead of “command:” but that didn’t work either.

---

<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 7, 2013, 8:48pm UTC](https://forum.ansible.com/t/how-to-split-action-into-multiline/13270/4 "2013-08-07T20:48:42Z")

</div>

This?

- name: Create SSH keypair files

command:  
command: ssh-keygen -f id\_rsa -N ‘’  
creates: id\_rsa

No, that won’t work. The command module doesn’t do key=value arguments.

---

<div class="post-metadata">

**Author:** ![C\_Morgan\_Hamill](https://avatars.discourse-cdn.com/v4/letter/c/ebca7d/32.png) [@C\_Morgan\_Hamill](https://forum.ansible.com/u/C_Morgan_Hamill)\
**Post date:** [August 8, 2013, 4:19pm UTC](https://forum.ansible.com/t/how-to-split-action-into-multiline/13270/5 "2013-08-08T16:19:52Z")

</div>

I've had no problems with the following, also:

&nbsp;&nbsp;&nbsp;&nbsp;- name: Update the Apache config  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;copy: src=httpd.conf  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest=/etc/httpd/httpd.conf

PyYAML, at least, seems to assign all of  
"src=httpd.conf dest=/etc/httpd/httpd.conf" as the value of the "copy"  
key. yamllint.com also seems to have no issues with this.

Anything no good about this that I'm missing?

---

<div class="post-metadata">

**Author:** ![John\_Jarvis](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@John\_Jarvis](https://forum.ansible.com/u/John_Jarvis)\
**Post date:** [August 11, 2013, 4:34pm UTC](https://forum.ansible.com/t/how-to-split-action-into-multiline/13270/6 "2013-08-11T16:34:27Z")

</div>

> # (3) YAML line continuations  
> - name: Update the Apache config  
> &nbsp;&nbsp;&nbsp;copy: \>  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src=httpd.conf  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest=/etc/httpd/httpd.conf

(3) Also seems to work without the "\>", for example:

&nbsp;&nbsp;&nbsp;&nbsp;copy:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src=httpd.conf  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest=/etc/httpd/httpd.conf

Formatting long lines is something we run into frequently with a lot  
of people working on the same playbooks, would a section on line  
continuation in the best practices section of the docs make sense?  
I wouldn't mind taking a stab at it if it's something the community  
would find useful.

-John

---

<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 11, 2013, 6:57pm UTC](https://forum.ansible.com/t/how-to-split-action-into-multiline/13270/7 "2013-08-11T18:57:44Z")

</div>

That would be great!

Probably should go here:

[http://www.ansibleworks.com/docs/YAMLSyntax.html](http://www.ansibleworks.com/docs/YAMLSyntax.html)

---

<div class="post-metadata">

**Author:** ![Adam\_Baxter](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@Adam\_Baxter](https://forum.ansible.com/u/Adam_Baxter)\
**Post date:** [November 23, 2013, 11:32pm UTC](https://forum.ansible.com/t/how-to-split-action-into-multiline/13270/8 "2013-11-23T23:32:42Z")

</div>

I just ran into the multiple line issue and found this thread via search.

> Probably should go here:
> 
> [http://www.ansibleworks.com/docs/YAMLSyntax.html](http://www.google.com/url?q=http%3A%2F%2Fwww.ansibleworks.com%2Fdocs%2FYAMLSyntax.html&sa=D&sntz=1&usg=AFQjCNFcwMF6F7nx0p8Uef7RFLp5CNEjNw)

Info about multiple lines doesn’t seem to be there, however it’s mentioned in [http://www.ansibleworks.com/docs/playbooks.html#tasks-list](http://www.ansibleworks.com/docs/playbooks.html#tasks-list)

This thread seems to be the most complete source of documentation on the topic 🙂  
Is it worth raising a GitHub issue for “incomplete” documentation or is the split-on-space method the preferred way of breaking long lines?

Thanks,  
Adam Baxter

---

<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:** [November 25, 2013, 6:44pm UTC](https://forum.ansible.com/t/how-to-split-action-into-multiline/13270/9 "2013-11-25T18:44:22Z")

</div>

You can file github tickets on the docs, sure.

Since the documentation is open source, an even better thing to do (if you are so inclined) is to patch the docs:

[https://github.com/ansible/ansible/tree/devel/docsite/rst](https://github.com/ansible/ansible/tree/devel/docsite/rst)

I think covering this in multiple places can’t hurt.
