From ca38c5c229d9af3929b372eeb0219a9cde9b69cb Mon Sep 17 00:00:00 2001 From: Merlin Mathesius Date: Sep 28 2017 00:52:53 +0000 Subject: Redirect qemu stderr to prevent ansible-playbook hang when run from a service When ansible-playbook is started from a service (such as cron or Jenkins) and uses a test subject launched by the dynamic inventory provider standard-inventory-qcow2 script, ansible-playbook hangs as if it were still waiting for the dynamic inventory to be gathered. The hang does not occur when run from the command line. The cause of the hang was identified to be the stderr file descriptor passed to qemu when it is started. This commit redirects stderr (and stdout) to the qemu machine log. --- diff --git a/inventory/standard-inventory-qcow2 b/inventory/standard-inventory-qcow2 index 24978dc..773e933 100755 --- a/inventory/standard-inventory-qcow2 +++ b/inventory/standard-inventory-qcow2 @@ -108,7 +108,7 @@ def start_qemu(image, cloudinit, log, portrange=(2222, 5555)): "-enable-kvm", "-snapshot", "-cdrom", cloudinit, "-net", "nic,model=virtio", "-net", "user,hostfwd=tcp:127.0.0.3:{0}-:22".format(port), "-device", "isa-serial,chardev=pts2", "-chardev", "file,id=pts2,path=" + log, - "-display", "none"], stdout=open(os.devnull, 'w')), port + "-display", "none"], stdout=open(log, 'a'), stderr=subprocess.STDOUT), port def host(image):