# Ansible - How register some line in variable

**URL:** <https://forum.ansible.com/t/ansible-how-register-some-line-in-variable/31800>\
**Category:** Ansible Project\
**Created:** [December 10, 2019, 2:20pm UTC](https://forum.ansible.com/t/ansible-how-register-some-line-in-variable/31800 "2019-12-10T14:20:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karther](https://avatars.discourse-cdn.com/v4/letter/k/3ec8ea/32.png) [@Karther](https://forum.ansible.com/u/Karther)\
**Post date:** [December 10, 2019, 2:20pm UTC](https://forum.ansible.com/t/ansible-how-register-some-line-in-variable/31800/1 "2019-12-10T14:20:54Z")

</div>

Hey Community ansible !! 🙂

I have some line texte with this content :

my first line  
my second line

my 3ème line  
my 4ème line

I want register all this line with one variable ? i don’t know if possible or not please ???

Can you help me please Community Ansible ? 🙂

Best regards,

Karther

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [December 10, 2019, 3:15pm UTC](https://forum.ansible.com/t/ansible-how-register-some-line-in-variable/31800/2 "2019-12-10T15:15:10Z")

</div>

> Hey Community ansible !! 🙂
> 
> I have some line texte with this content :
> 
> my first line  
> my second line
> 
> my 3ème line  
> my 4ème line
> 
> I want register all this line with one variable ? i don't know if possible or not please ???
> 
> Can you help me please Community Ansible ? 🙂
> 
> Best regards,
> 
> Karther

Sorry I have no idea what you want to achieve.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Karther](https://avatars.discourse-cdn.com/v4/letter/k/3ec8ea/32.png) [@Karther](https://forum.ansible.com/u/Karther)\
**Post date:** [December 10, 2019, 3:32pm UTC](https://forum.ansible.com/t/ansible-how-register-some-line-in-variable/31800/3 "2019-12-10T15:32:45Z")

</div>

Hey,

I want register some line in one variable …

I have some line :

my first line  
my second line

my 3ème line  
my 4ème line

I want that my variable =

my first line  
my second line

my 3ème line  
my 4ème line

Thanks for your help !! 🙂

Regards,

---

<div class="post-metadata">

**Author:** ![j1f0x](https://avatars.discourse-cdn.com/v4/letter/j/ce73a5/32.png) [@j1f0x](https://forum.ansible.com/u/j1f0x)\
**Post date:** [December 12, 2019, 9:48pm UTC](https://forum.ansible.com/t/ansible-how-register-some-line-in-variable/31800/4 "2019-12-12T21:48:49Z")

</div>

Hi,

maybe you try this:

```auto
include_newlines: |
            exactly as you see
            will appear these three
            lines of poetry

fold_newlines: >
            this is really a
            single line of text
            despite appearances

```

see: [https://docs.ansible.com/ansible/latest/reference\_appendices/YAMLSyntax.html](https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html)

---

<div class="post-metadata">

**Author:** ![Karther](https://avatars.discourse-cdn.com/v4/letter/k/3ec8ea/32.png) [@Karther](https://forum.ansible.com/u/Karther)\
**Post date:** [December 31, 2019, 8:34am UTC](https://forum.ansible.com/t/ansible-how-register-some-line-in-variable/31800/5 "2019-12-31T08:34:57Z")

</div>

Hey,

no I have this result with this task :

“msg”: “exactly as you see\nwill appear these three\nlines of poetry\n”

Can you help me please ?? 🙂

Thanks very much,

Best Regards,

Karther

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [December 31, 2019, 9:26am UTC](https://forum.ansible.com/t/ansible-how-register-some-line-in-variable/31800/6 "2019-12-31T09:26:44Z")

</div>

The playbook below is self-explaining

- hosts: localhost  
&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;msg: |  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exactly as you see  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;will appear these three  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lines of poetry  
&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "{{ msg }}"  
&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "{{ msg.split('\n') }}"  
&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "{{ msg.split('\n')[:-1] }}"

gives

ok: [localhost] =\> {  
&nbsp;&nbsp;&nbsp;&nbsp;"msg": "exactly as you see\nwill appear these three\nlines of poetry\n"  
}

ok: [localhost] =\> { "msg": [  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"exactly as you see",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"will appear these three",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"lines of poetry",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;""  
&nbsp;&nbsp;&nbsp;&nbsp;]  
}

ok: [localhost] =\> { "msg": [  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"exactly as you see",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"will appear these three",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"lines of poetry"  
&nbsp;&nbsp;&nbsp;&nbsp;]  
}

HTH,

&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [December 31, 2019, 9:13pm UTC](https://forum.ansible.com/t/ansible-how-register-some-line-in-variable/31800/7 "2019-12-31T21:13:33Z")

</div>

Here is another way:

`

- hosts: localhost  
gather\_facts: no

tasks:

- name: register file contents  
shell: cat /path/to/file/that/contains/text  
register: file\_contents

- name: show file contents  
debug:  
msg: ‘{{ file\_contents.stdout }}’  
`

or you can use a lookup

`

- hosts: localhost  
gather\_facts: no  
tasks:

- name: register file contents  
set\_fact:  
file\_contents: “{{ lookup(‘file’, ‘/path/to/file/that/contains/text’ )}}”

- name: show file contents  
debug:  
msg: “{{ file\_contents }}”

`

Hope this helps

Jon
