# Export debug msg to a file

**URL:** <https://forum.ansible.com/t/export-debug-msg-to-a-file/34236>\
**Category:** Ansible Project\
**Created:** [November 24, 2020, 10:47pm UTC](https://forum.ansible.com/t/export-debug-msg-to-a-file/34236 "2020-11-24T22:47:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bilkam](https://avatars.discourse-cdn.com/v4/letter/b/e8c25b/32.png) [@bilkam](https://forum.ansible.com/u/bilkam)\
**Post date:** [November 24, 2020, 10:47pm UTC](https://forum.ansible.com/t/export-debug-msg-to-a-file/34236/1 "2020-11-24T22:47:06Z")

</div>

Hello

Need some assistance to send to a text file a message that appears in debug msg.  
my uri task give me the flow msg  
“msg”: [

“JOB-1”,  
“JOB-2”,  
" JOB- 3 ",  
" JOB- 4 ",  
" JOB- 5 ",  
" JOB- 6 ",  
" JOB- 7 "  
]  
and I need to add task on the playbook to send this msg to specific file like this

cat jobs\_lists.txt

JOB-1  
JOB-2  
JOB- 3  
JOB- 4  
JOB- 5  
JOB- 6  
JOB- 7

Appreciate your help.  
Regards

---

<div class="post-metadata">

**Author:** ![Roberto\_J\_R\_Paz](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@Roberto\_J\_R\_Paz](https://forum.ansible.com/u/Roberto_J_R_Paz)\
**Post date:** [November 25, 2020, 7:15am UTC](https://forum.ansible.com/t/export-debug-msg-to-a-file/34236/2 "2020-11-25T07:15:10Z")

</div>

The text you print in the debug task is previously stored in a variable?  
If that’s the case, you can write the variable **stdout\_lines** attribute to a local file using **lineinfile** module and **delegate\_to: localhost** , so this is writted locally.

---

<div class="post-metadata">

**Author:** ![bilkam](https://avatars.discourse-cdn.com/v4/letter/b/e8c25b/32.png) [@bilkam](https://forum.ansible.com/u/bilkam)\
**Post date:** [November 25, 2020, 8:19am UTC](https://forum.ansible.com/t/export-debug-msg-to-a-file/34236/3 "2020-11-25T08:19:32Z")

</div>

The text you print in the debug task is previously stored in a variable? **No**

- name: Display all Jobs Names  
ansible.builtin.debug:  
msg: “{{ Jobs.json | json\_query(‘Jobs.Jobs[\*].Name’)}}”

ok: [localhost] =\> {  
“changed”: false,  
“msg”: [  
“JOB-1”,  
“JOB-2”,  
“JOB-3”,  
“JOB-4”,  
“JOB-9”,  
“JOB-8”,  
“JOB-7”  
]  
}

and then I need task to save the list of the job name on specific file:

cat jobs\_lists.txt

JOB-1  
JOB-2  
JOB- 3  
JOB- 4  
JOB- 5  
JOB- 6  
JOB- 7

Regards,

---

<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:** [November 25, 2020, 8:52am UTC](https://forum.ansible.com/t/export-debug-msg-to-a-file/34236/4 "2020-11-25T08:52:28Z")

</div>

> The text you print in the debug task is previously stored in a variable? \*No\*  
> - name: Display all Jobs Names  
> ansible.builtin.debug:  
> msg: "{{ Jobs.json | json\_query('Jobs.Jobs[\*].Name')}}"
> 
> ok: [localhost] =\> {  
> "changed": false,  
> "msg": [  
> "JOB-1",  
> "JOB-2",  
> "JOB-3",  
> "JOB-4",  
> "JOB-9",  
> "JOB-8",  
> "JOB-7"  
> ]  
> }
> 
> and then I need task to save the list of the job name on specific file:
> 
> cat jobs\_lists.txt
> 
> ```
> JOB\-1
> JOB\-2
> JOB\- 3 
> JOB\- 4 
> JOB\- 5 
> JOB\- 6 
> JOB\- 7
> 
> ```
> 
> Regards,

You can use a copy task with is delegated to localhost:

&nbsp;&nbsp;- name: Write job file  
&nbsp;&nbsp;&nbsp;&nbsp;copy:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;content: "{{ Jobs.json | json\_query('Jobs.Jobs[\*].Name') | join('\n') }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: /tmp/job\_lists.txt  
&nbsp;&nbsp;&nbsp;&nbsp;delegate\_to: localhost

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

---

<div class="post-metadata">

**Author:** ![bilkam](https://avatars.discourse-cdn.com/v4/letter/b/e8c25b/32.png) [@bilkam](https://forum.ansible.com/u/bilkam)\
**Post date:** [November 25, 2020, 9:14am UTC](https://forum.ansible.com/t/export-debug-msg-to-a-file/34236/5 "2020-11-25T09:14:16Z")

</div>

Just what I need.

Thanks for your support
