ansible-playbook truncating results

Hi

I’m new to ansible so still copying examples. I have this playbook example which appears to work…but is truncating the results:

[root@adm1-lon ansible]# cat ps.yaml

  • hosts: development
    gather_facts: no
    tasks:

  • shell: “ps -eo ppid,pid,user,pcpu,args”
    register: ps

  • debug: var=“ps.stdout_lines”
    [root@adm1-lon ansible]#

and when I run it…

[root@adm1-lon ansible]# ansible-playbook -i hosts ps.yaml

PLAY [development] ************************************************************

TASK: [shell ps -eo ppid,pid,user,pcpu,args] **********************************
changed: [appl12-lon.global.tudor.com]

TASK: [debug var=“{{ps.stdout_lines}}”] ***************************************
ok: [appl12-lon.global.tudor.com] => {
”:
}

PLAY RECAP ********************************************************************
appl12-lon.global.tudor.com : ok=2 changed=1 unreachable=0 failed=0

[root@adm1-lon ansible]#

However, if I change the yaml to limit the line count like so:

[root@adm1-lon ansible]# cat ps.yaml

  • hosts: development
    gather_facts: no
    tasks:

  • shell: “ps -eo ppid,pid,user,pcpu,args | head -200”
    register: ps

  • debug: var=“ps.stdout_lines”
    [root@adm1-lon ansible]#

I then get my results…although only the first 200 lines:

[root@adm1-lon ansible]# ansible-playbook -i hosts ps.yaml

PLAY [development] ************************************************************

TASK: [shell ps -eo ppid,pid,user,pcpu,args | head -200] **********************
changed: [appl12-lon.global.tudor.com]

TASK: [debug var=“ps.stdout_lines”] *******************************************
ok: [appl12-lon.global.tudor.com] => {
“ps.stdout_lines”: [
" PPID PID USER %CPU COMMAND",
" 0 1 root 0.0 /sbin/init",
" 0 2 root 0.0 [kthreadd]“,
" 2 3 root 0.0 [migration/0]”,
" 2 4 root 0.0 [ksoftirqd/0]“,
" 2 5 root 0.0 [migration/0]”,
" 2 6 root 0.0 [migration/1]“,
" 2 7 root 0.0 [migration/1]”,

System details:

[root@adm1-lon ansible]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.4 (Santiago)
[root@adm1-lon ansible]# rpm -qa | grep -i ansible
ansible-1.5.3-1.el6.noarch
[root@adm1-lon ansible]#

Any ideas?

Do you mean you only get 200 lines of the standard output, or you don’t see the rest of the playbook run?

Thanks!

I don’t get ANY results…unless I limit the line count.

Here you can see my ps.yaml and the empty results:

[root@adm1-lon ansible]#
[root@adm1-lon ansible]# cat ps.yaml

  • hosts: development
    gather_facts: no
    tasks:

  • shell: “ps -eo ppid,pid,user,pcpu,args”
    register: ps

  • debug: var=“ps.stdout_lines”
    [root@adm1-lon ansible]#

[root@adm1-lon ansible]# ansible-playbook -i hosts ps.yaml

PLAY [development] ************************************************************

TASK: [shell ps -eo ppid,pid,user,pcpu,args] **********************************
changed: [appl12-lon.global.tudor.com]

TASK: [debug var=“ps.stdout_lines”] *******************************************
ok: [appl12-lon.global.tudor.com] => {
“ps.stdout_lines”: []
}

PLAY RECAP ********************************************************************
appl12-lon.global.tudor.com : ok=2 changed=1 unreachable=0 failed=0

[root@adm1-lon ansible]#

The all I do is add a “| tail -210” and suddenly I start getting results:

[root@adm1-lon ansible]# cat ps.yaml

  • hosts: development
    gather_facts: no
    tasks:

  • shell: “ps -eo ppid,pid,user,pcpu,args | tail -210”
    register: ps

  • debug: var=“ps.stdout_lines”
    [root@adm1-lon ansible]#
    [root@adm1-lon ansible]# ansible-playbook -i hosts ps.yaml

PLAY [development] ************************************************************

TASK: [shell ps -eo ppid,pid,user,pcpu,args | tail -210] **********************
changed: [appl12-lon.global.tudor.com]

TASK: [debug var=“ps.stdout_lines”] *******************************************
ok: [appl12-lon.global.tudor.com] => {
“ps.stdout_lines”: [
" 2748 2793 68 0.0 hald-addon-acpi: listening on acpid socket /var/run/acpid.socket",
" 1 2805 bbushby 0.0 /bin/sh /etc/vnc/xstartup",
" 2805 2809 bbushby 0.0 /usr/bin/ck-xinit-session /usr/bin/ssh-agent /etc/X11/xinit/Xclients",
" 1 2825 bbushby 0.0 dbus-launch --sh-syntax --exit-with-session",
" 1 2827 bbushby 0.0 /bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session",
" 2809 2855 bbushby 0.0 /usr/bin/gnome-session",
" 2855 2856 bbushby 0.0 /usr/bin/ssh-agent /etc/X11/xinit/Xclients",

I was wondering about paramiko buffers/max char reads?

This is not a “line count” issue because it varies from system to system, it’s more a “max chars” limit that renders the result blank.

To make things more confusing…I created a large file with thousands of lines with many thousands of chars and I can “cat” it without any truncation.

Hmm, ok, I think I understand now, you’re not seeing any stdout from that task.

Can you please debug the full value and show me what you get (without the tail?)

  • debug: var=ps

I’m also interested in your Ansible version. (Also, are you sure you are using paramiko? Perhaps explicitly specify with -c, as I want to make sure of the connection type).

Thanks!

Here we go…I simplified the “ps” command

[root@adm1-lon ansible]#
[root@adm1-lon ansible]# cat ps.yaml

  • hosts: development
    gather_facts: no
    tasks:

  • shell: “ps -ef”
    register: ps

  • debug: var=ps
    [root@adm1-lon ansible]#
    [root@adm1-lon ansible]# ansible-playbook -i hosts ps.yaml

PLAY [development] ************************************************************

TASK: [shell ps -ef] **********************************************************
changed: [appl12-lon.global.tudor.com]

TASK: [debug var=ps] **********************************************************
ok: [appl12-lon.global.tudor.com] => {
“ps”: {
“changed”: true,
“cmd”: "ps -ef ",
“delta”: “0:00:00.025065”,
“end”: “2014-08-14 14:00:52.483265”,
“invocation”: {
“module_args”: “ps -ef”,
“module_name”: “shell”
},
“rc”: 0,
“start”: “2014-08-14 14:00:52.458200”,
“stderr”: “”,
“stdout”: “”,
“stdout_lines”:
}
}

PLAY RECAP ********************************************************************
appl12-lon.global.tudor.com : ok=2 changed=1 unreachable=0 failed=0

[root@adm1-lon ansible]#

I think it has something to do with the way ansible is parsing the shell command. If I change the command to simply “ps” …then it works 100% on my 3 test servers…although “ps” on it’s does generate less characters.

[root@adm1-lon ansible]#
[root@adm1-lon ansible]#
[root@adm1-lon ansible]# cat ps.yaml

  • hosts: development
    gather_facts: no
    tasks:

  • shell: “ps”
    register: ps

  • debug: var=ps
    [root@adm1-lon ansible]#
    [root@adm1-lon ansible]# ansible-playbook -i hosts ps.yaml

PLAY [development] ************************************************************

TASK: [shell ps] **************************************************************
changed: [appl12-lon.global.tudor.com]

TASK: [debug var=ps] **********************************************************
ok: [appl12-lon.global.tudor.com] => {
“ps”: {
“changed”: true,
“cmd”: "ps ",
“delta”: “0:00:00.016743”,
“end”: “2014-08-14 14:03:04.342171”,
“invocation”: {
“module_args”: “ps”,
“module_name”: “shell”
},
“rc”: 0,
“start”: “2014-08-14 14:03:04.325428”,
“stderr”: “”,
“stdout”: " PID TTY TIME CMD\n 1 ? 00:00:04 init\n 2 ? 00:00:00 kthreadd\n 3 ? 00:00:09 migration/0\n 4 ? 00:02:37 ksoftirqd/0\n 5 ? 00:00:00 migration/0\

…cut

Here I run a simple “cat /tmp/file” which returns 768k+ characters…so perhaps not just a simple max character/buffer issue.

[root@adm1-lon ansible]#
[root@adm1-lon ansible]# cat count.yaml

  • hosts: development
    gather_facts: no
    tasks:

  • shell: cat /tmp/test-count
    register: count

  • debug: var=“{{count.stdout_lines}}”
    [root@adm1-lon ansible]#
    [root@adm1-lon ansible]# ansible-playbook -i hosts count.yaml | wc -c
    768386
    [root@adm1-lon ansible]#

That’s really weird - all shell commands are parsed the same.

before I ask you to file a bug on this, can you share what version of Ansible you are using?

Aside on one thing really quickly:

" - debug: var=“{{count.stdout_lines}}”

This really should be:

  • debug: msg=“{{ count.stdout_lines }}”

Though it appears to work for simple integers, 768386 is not a variable name, so that’s why it’s weird.

  • debug: var=count.stdout_lines

should be legit.