Browse Source

fix import issue and add config opt to the run object

changes/53/712253/1
Mathieu Bultel 2 years ago
parent
commit
0c8ea35843
  1. 13
      validations_libs/ansible.py
  2. 38
      validations_libs/run.py

13
validations_libs/ansible.py

@ -28,6 +28,14 @@ from validations_libs import utils
LOG = logging.getLogger(__name__ + ".ansible")
# NOTE(cloudnull): This is setting the FileExistsError for py2 environments.
# When we no longer support py2 (centos7) this should be
# removed.
try:
FileExistsError = FileExistsError
except NameError:
FileExistsError = OSError
class Ansible(object):
@ -259,8 +267,7 @@ class Ansible(object):
gathering_policy='smart',
extra_env_variables=None, parallel_run=False,
callback_whitelist=None, ansible_cfg=None,
ansible_timeout=30, reproduce_command=False,
fail_on_rc=True):
ansible_timeout=30):
if not playbook_dir:
playbook_dir = workdir
@ -342,4 +349,4 @@ class Ansible(object):
runner = ansible_runner.Runner(config=runner_config)
status, rc = runner.run()
return playbook, rc, status
return runner.stdout.name, playbook, rc, status

38
validations_libs/run.py

@ -30,10 +30,9 @@ class Run(object):
self.log = logging.getLogger(__name__ + ".Run")
def run_validations(self, playbook, inventory,
group=None,
extra_vars=None,
validations_dir=None,
validation_name=None):
group=None, extra_vars=None, validations_dir=None,
validation_name=None, extra_env_var=None,
ansible_cfg=None):
self.log = logging.getLogger(__name__ + ".run_validations")
@ -63,23 +62,24 @@ class Run(object):
results = []
with v_utils.TempDirs(chdir=False) as tmp:
for playbook in playbooks:
_playbook, _rc, _status = run_ansible.run(
workdir=tmp,
playbook=playbook,
playbook_dir=(
validations_dir if
validations_dir else
constants.
ANSIBLE_VALIDATION_DIR),
parallel_run=True,
inventory=inventory,
output_callback='validation_json',
quiet=True,
extra_vars=extra_vars,
gathering_policy='explicit')
stdout_file, _playbook, _rc, _status = run_ansible.run(
workdir=tmp,
playbook=playbook,
playbook_dir=(validations_dir if
validations_dir else
constants.ANSIBLE_VALIDATION_DIR),
parallel_run=True,
inventory=inventory,
output_callback='validation_json',
quiet=True,
extra_vars=extra_vars,
extra_env_variables=extra_env_var,
ansible_cfg=ansible_cfg,
gathering_policy='explicit')
results.append({'validation': {
'playbook': _playbook,
'rc_code': _rc,
'status': _status
'status': _status,
'stdout_file': stdout_file
}})
return results
Loading…
Cancel
Save