How to get real time output from ansible-playbook process when called in PHP?

2,250 views
Skip to first unread message

Sally Paner

unread,
Jan 20, 2016, 8:24:13 AM1/20/16
to Ansible Project
I have a simple PHP script that runs ansible-playbook and polls the output.  It seems that ansible runs to completion before it displays the output.
This is my simple code:
(process.php)
$handle = popen("ansible-playbook set-mysqld-max-connection-with-template.yml", "r");

while(!feof($handle)) {
$buffer = fgets($handle);
      echo $buffer . "\n";
   usleep(100000); //sleep for 0.1 seconds
}
pclose($handle);

Output:
PLAY [web] ********************************************************************

GATHERING FACTS ***************************************************************
ok: [selenium1.example.com]

TASK: [set-mysqld-max-connection-with-template | set mysqld (my.cnf) max_connection with template] ***
ok: [selenium1.example.com]

PLAY RECAP ********************************************************************
selenium1.example.com       : ok=2    changed=0    unreachable=0    failed=0  



Brian Coca

unread,
Jan 20, 2016, 9:04:35 AM1/20/16
to Ansible Project
There is no currently available 'intermediate updates' feature.
> --
> 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/b159af10-7fce-4b69-b6c1-4eb7191d89aa%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Brian Coca

Sally Paner

unread,
Jan 21, 2016, 6:36:30 AM1/21/16
to Ansible Project
Hi Brian;


Thanks for the reply.  I am just wondering that if I run ansible-playbook directly on the command line, it gives me real-time output, but if called from PHP it seems that ansible-playbook waits to finish the playbook before it returns any output.

Brian Coca

unread,
Jan 21, 2016, 8:51:06 AM1/21/16
to Ansible Project

Sally Paner

unread,
Jan 27, 2016, 5:57:01 AM1/27/16
to Ansible Project
Hi Brian;

I've resolved my problem by installing ansible through git because it pulls the latest version of ansible.  My previous ansible was installed through yum.  Thanks.  
Reply all
Reply to author
Forward
0 new messages