BUG? 'stdout_lines | to_nice_json' crashing Ansible server

58 views
Skip to first unread message

John Harmon

unread,
Aug 1, 2018, 5:36:45 PM8/1/18
to Ansible Project
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:
---
- hosts: "{{ host }}"
  tasks
:
   
- name: Gather used sudo commands
      shell
: "/home/myuser/scripts/dba_history.sh"
     
register: commands

   
- name: Write results
      shell
: "echo {{ commands.stdout_lines | to_nice_json }} >> /tmp/dba_commands.txt"
      delegate_to
: localhost

It crashes when writing results:
ansible:/playbooks/one-offs # ansible-playbook ./dba_sudo_commands.yml -e host=labenv

PLAY
 
[labenv]
****************************************************************************************************************************************************************************************************************************

TASK
 
[Gathering Facts]
*******************************************************************************************************************************************************************************************************************
ok
: [labebs-apps1]
ok
: [labebs-db]

TASK
 
[Gather used sudo commands]
*********************************************************************************************************************************************************************************************************
changed
: [labebs-apps1]
changed
: [labebs-db]

TASK
 
[Write results]
*********************************************************************************************************************************************************************************************************************
Connection to ansible closed by remote host.
Connection to ansible closed.

Sample output of the script without 'to_nice_json':
ok: [labebs-apps1] => {
   
"commands": {
       
"changed": true,
       
"cmd": "/home/myuser/scripts/dba_history.sh",
       
"delta": "0:00:00.109182",
       
"end": "2018-08-01 21:27:47.942792",
       
"failed": false,
       
"rc": 0,
       
"start": "2018-08-01 21:27:47.833610",
       
"stderr": "",
       
"stderr_lines": [],
       
"stdout": "cd /labebs/inst/apps/LABEBS_labebs-apps1/ora/10.1.3/Apache/Apache/bin\ncd /labebs/inst/apps/LABEBS_labebs-apps1/ora/10.1.3/Apache/Apache/bin\ncd /labebs/inst/apps/LABEBS_labebs-apps1/ora/10.1.3/Apache/Apache/bin\ncd /labebs/inst/apps/LABEBS_labebs-apps1/ora/10.1.3/Apache/Apache/bin\ncd /labebs/inst/apps/LABEBS_labebs-apps1/ora/10.1.3/Apache/Apache/bin\ncd .gi\ncd .git/\ncd /labebs/inst/apps/LABEBS_labebs-apps1/ora/10.1.3/Apache/Apache/bin\ncd scripts/\nvi config \ncd /labebs/inst/apps/LABEBS_labebs-apps1/ora/10.1.3/Apache/Apache/bin\ncd /etc/rsyslog.d/\ncd /labebs/inst/apps/LABEBS_labebs-apps1/ora/10.1.3/Apache/Apache/bin\nclear\ninit 0\nrsyslogd\nrsyslogd -c5\nrsyslogd -N1\ncat 91-applmgr.conf \ncd /etc/security/limits.d/\ncd /labebs/inst/apps/LABEBS_labebs-apps1/ora/10.1.3/Apache/Apache/bin\nps aux | grep smon\ncat 91-applmgr.conf \ncd /etc/security/limits.d/\ncd /labebs/\ncd /labebs/inst/apps/LABEBS_labebs-apps1/ora/10.1.3/Apache/Apache/bin\nps aux | grep smon\nvi /etc/fstab \nreboot",
       
"stdout_lines": [
           
"cd /labebs/inst/apps/LABEBS_labebs-apps1/ora/10.1.3/Apache/Apache/bin",
           
"cd /labebs/inst/apps/LABEBS_labebs-apps1/ora/10.1.3/Apache/Apache/bin",
           
"cd /labebs/inst/apps/LABEBS_labebs-apps1/ora/10.1.3/Apache/Apache/bin",
           
"cd /labebs/inst/apps/LABEBS_labebs-apps1/ora/10.1.3/Apache/Apache/bin",
           
"cd /labebs/inst/apps/LABEBS_labebs-apps1/ora/10.1.3/Apache/Apache/bin",
           
"cd .gi",
           
"cd .git/",
           
"cd /labebs/inst/apps/LABEBS_labebs-apps1/ora/10.1.3/Apache/Apache/bin",
           
"cd scripts/",
           
"vi config ",
           
"cd /labebs/inst/apps/LABEBS_labebs-apps1/ora/10.1.3/Apache/Apache/bin",
           
"cd /etc/rsyslog.d/",
           
"cd /labebs/inst/apps/LABEBS_labebs-apps1/ora/10.1.3/Apache/Apache/bin",
           
"clear",
           
"init 0",
           
"rsyslogd",
           
"rsyslogd -c5",
           
"rsyslogd -N1",
           
"cat 91-applmgr.conf ",
           
"cd /etc/security/limits.d/",
           
"cd /labebs/inst/apps/LABEBS_labebs-apps1/ora/10.1.3/Apache/Apache/bin",
           
"ps aux | grep smon",
           
"cat 91-applmgr.conf ",
           
"cd /etc/security/limits.d/",
           
"cd /labebs/",
           
"cd /labebs/inst/apps/LABEBS_labebs-apps1/ora/10.1.3/Apache/Apache/bin",
           
"ps aux | grep smon",
           
"vi /etc/fstab ",
           
"reboot"
       
]
   
}
}




Matt Martz

unread,
Aug 1, 2018, 5:40:56 PM8/1/18
to ansible...@googlegroups.com
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.



--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/833fdc77-151b-42cf-815c-6903a21fd918%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Matt Martz
@sivel
sivel.net

John Harmon

unread,
Aug 1, 2018, 5:46:41 PM8/1/18
to Ansible Project
Thanks Matt.  I tried the '| quote' and it did not crash this time.  I will look into the template module.

John Harmon

unread,
Aug 1, 2018, 6:08:35 PM8/1/18
to Ansible Project


On Wednesday, August 1, 2018 at 3:46:41 PM UTC-6, John Harmon wrote:
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

Kai Stian Olstad

unread,
Aug 2, 2018, 2:23:29 AM8/2/18
to ansible...@googlegroups.com
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

--
Kai Stian Olstad

Badraj Angirekula

unread,
Aug 2, 2018, 3:54:32 AM8/2/18
to ansible...@googlegroups.com
Hi all I am facing error in aws please help.


[root@server2 ~]# ssh -i bhadra.pem ec2-...@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).

Thanks & Regards,
BADRAJ ANGIREKULA

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/6aebd3c31e9d0533bfcb4b5a377fd9ae%40olstad.com.

durga prasad

unread,
Aug 2, 2018, 3:58:54 AM8/2/18
to ansible...@googlegroups.com
Hi 

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

$ sudo chmod  0644  bhadra.pem

Thanks & Regards,
Durgaprasad 

On Thu, Aug 2, 2018 at 1:24 PM, Badraj Angirekula <badraj.a...@gmail.com> wrote:
Hi all I am facing error in aws please help.


[root@server2 ~]# ssh -i bhadra.pem ec2-...@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).

Thanks & Regards,
BADRAJ ANGIREKULA
Reply all
Reply to author
Forward
0 new messages