BUG? 'stdout_lines | to_nice_json' crashing Ansible server

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:

`

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.

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

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

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

   - name: Write results
     copy:
       content: '{{ commands.stdout_lines | to_nice_json }}'
       dest: /tmp/dba_commands.txt
     delegate_to: localhost

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
The authenticity of host ‘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,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).

Hi

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

$ sudo chmod 0644 bhadra.pem

Thanks & Regards,
Durgaprasad