mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00: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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user