# BUG?  'stdout\_lines | to\_nice\_json' crashing Ansible server

**URL:** <https://forum.ansible.com/t/bug-stdout-lines-to-nice-json-crashing-ansible-server/28229>\
**Category:** Ansible Project\
**Created:** [August 1, 2018, 9:36pm UTC](https://forum.ansible.com/t/bug-stdout-lines-to-nice-json-crashing-ansible-server/28229 "2018-08-01T21:36:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [August 1, 2018, 9:36pm UTC](https://forum.ansible.com/t/bug-stdout-lines-to-nice-json-crashing-ansible-server/28229/1 "2018-08-01T21:36:45Z")

</div>

I have a bash script on each server that gathers some information and then stores that info in the commands variable. If I write ‘commands.stdout | to\_nice\_json’ to a file, everything is fine. If I use ‘commands.stdout\_lines | to\_nice\_json’ it immediately reboots my Ansible server. If I remove the ‘to\_nice\_json’ it doesn’t have an issue. Should I file a bug? or do you have any other theories?

ansible-2.6.1-1.el7.noarch

Playbook:

`

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [August 1, 2018, 9:40pm UTC](https://forum.ansible.com/t/bug-stdout-lines-to-nice-json-crashing-ansible-server/28229/2 "2018-08-01T21:40:11Z")

</div>

I’m guessing that the result of `{{ commands.stdout_lines | to_nice_json }}` is breaking out of the echo statement.

You probably want to make use of `|quote` filter. Such as `shell: "echo {{ commands.stdout_lines | to_nice_json | quote }} >> /tmp/dba_commands.txt"`

However, I’d recommend using the template module instead to write that out.

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [August 1, 2018, 9:46pm UTC](https://forum.ansible.com/t/bug-stdout-lines-to-nice-json-crashing-ansible-server/28229/3 "2018-08-01T21:46:41Z")

</div>

Thanks Matt. I tried the ‘| quote’ and it did not crash this time. I will look into the template module.

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [August 1, 2018, 10:08pm UTC](https://forum.ansible.com/t/bug-stdout-lines-to-nice-json-crashing-ansible-server/28229/4 "2018-08-01T22:08:35Z")

</div>

I couldn’t get it to write it with the template module… but I was able to write it fine with lineinfile

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 2, 2018, 6:23am UTC](https://forum.ansible.com/t/bug-stdout-lines-to-nice-json-crashing-ansible-server/28229/5 "2018-08-02T06:23:19Z")

</div>

In your shell task you append to the file, but if replacing the file every time you run ansible-playbook is OK, this should work

&nbsp;&nbsp;&nbsp;- name: Write results  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;copy:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;content: '{{ commands.stdout\_lines | to\_nice\_json }}'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: /tmp/dba\_commands.txt  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delegate\_to: localhost

---

<div class="post-metadata">

**Author:** ![Badraj\_Angirekula](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@Badraj\_Angirekula](https://forum.ansible.com/u/Badraj_Angirekula)\
**Post date:** [August 2, 2018, 7:54am UTC](https://forum.ansible.com/t/bug-stdout-lines-to-nice-json-crashing-ansible-server/28229/6 "2018-08-02T07:54:23Z")

</div>

Hi all I am facing error in aws please help.

[root@server2 ~]# ssh -i bhadra.pem ec2-user@ec2-50-112-6-190.us-west-2.compute. [amazonaws.com](http://amazonaws.com)  
The authenticity of host ‘[ec2-50-112-6-190.us-west-2.compute.amazonaws.com](http://ec2-50-112-6-190.us-west-2.compute.amazonaws.com) (50.1 12.6.190)’ can’t be established.  
ECDSA key fingerprint is 1f:1b:6b:13:d2:7a:b5:a4:4b:78:84:b7:98:05:ab:39.  
Are you sure you want to continue connecting (yes/no)? yes  
Warning: Permanently added ‘[ec2-50-112-6-190.us-west-2.compute.amazonaws.com](http://ec2-50-112-6-190.us-west-2.compute.amazonaws.com),50. 112.6.190’ (ECDSA) to the list of known hosts.  
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @  
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  
Permissions 0644 for ‘bhadra.pem’ are too open.  
It is required that your private key files are NOT accessible by others.  
This private key will be ignored.  
bad permissions: ignore key: bhadra.pem  
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

---

<div class="post-metadata">

**Author:** ![durga\_prasad](https://avatars.discourse-cdn.com/v4/letter/d/97f17d/32.png) [@durga\_prasad](https://forum.ansible.com/u/durga_prasad)\
**Post date:** [August 2, 2018, 7:58am UTC](https://forum.ansible.com/t/bug-stdout-lines-to-nice-json-crashing-ansible-server/28229/7 "2018-08-02T07:58:43Z")

</div>

Hi

Please give permission for your key use below of commands :-

$ sudo chmod 0644 bhadra.pem

Thanks & Regards,  
Durgaprasad
