mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
gen_distribution_version_testcase.py should fail if ansible run fails (#17693)
Currently, "ansible localhost -m setup" can fail silently during the run of gen_distribution_version_testcase.py, resulting in incorrect output. Use check_output() rather than communicate() and handle the exception if we get a nonzero return value.
This commit is contained in:
parent
362b682f1c
commit
db276373e5
1 changed files with 10 additions and 1 deletions
|
@ -12,6 +12,7 @@ import platform
|
|||
import os.path
|
||||
import subprocess
|
||||
import json
|
||||
import sys
|
||||
|
||||
filelist = [
|
||||
'/etc/oracle-release',
|
||||
|
@ -46,7 +47,15 @@ dist = platform.dist()
|
|||
|
||||
|
||||
facts = ['distribution', 'distribution_version', 'distribution_release', 'distribution_major_version', 'os_family']
|
||||
ansible_out = subprocess.Popen(['ansible', 'localhost', '-m', 'setup'], stdout=subprocess.PIPE).communicate()[0]
|
||||
|
||||
try:
|
||||
ansible_out = subprocess.check_output(
|
||||
['ansible', 'localhost', '-m', 'setup'])
|
||||
except subprocess.CalledProcessError as e:
|
||||
print("ERROR: ansible run failed, output was: \n")
|
||||
print(e.output)
|
||||
sys.exit(e.returncode)
|
||||
|
||||
parsed = json.loads(ansible_out[ansible_out.index('{'):])
|
||||
ansible_facts = {}
|
||||
for fact in facts:
|
||||
|
|
Loading…
Reference in a new issue