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 to /dev/null.
The following script can be used to demonstrate the current problem and the fix. It runs normally from the command line, but will hang if started from cron, batch, etc. (Be sure to manually kill the lingering qemu process after the hang, and clean up the temporary directory.)
#!/bin/bash
mkdir/tmp/workspace$$cd/tmp/workspace$$
cat->ping.yml<<EOF---- hosts: localhost tasks: - ping:EOF
curl-Loatomic.qcow2https://ftp-stud.hs-esslingen.de/pub/Mirrors/alt.fedoraproject.org/atomic/stable/Fedora-Atomic-26-20170707.1/CloudImages/x86_64/images/Fedora-Atomic-26-20170707.1.x86_64.qcow2
curl-Lostandard-inventory-qcow2https://pagure.io/fork/merlinm/standard-test-roles/raw/fix-hang-when-run-from-service/f/inventory/standard-inventory-qcow2
chmod+xstandard-inventory-qcow2
exportTEST_SUBJECTS=$PWD/atomic.qcow2
exportANSIBLE_INVENTORY=$PWD/standard-inventory-qcow2
ansible-playbookping.yml
exportANSIBLE_INVENTORY=/usr/share/ansible/inventory/standard-inventory-qcow2
# this will hang if run from cron, batch, etc.
ansible-playbookping.yml
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 to /dev/null.
The following script can be used to demonstrate the current problem and the fix. It runs normally from the command line, but will hang if started from cron, batch, etc. (Be sure to manually kill the lingering qemu process after the hang, and clean up the temporary directory.)