From 4bbffdb814a87bae969eb48781da36c992f1e8de Mon Sep 17 00:00:00 2001 From: Matt Tarkington Date: Fri, 8 Nov 2024 09:49:54 -0500 Subject: [PATCH] update nac_dc_validate to check if iac-validate is installed (#224) --- plugins/action/common/nac_dc_validate.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/plugins/action/common/nac_dc_validate.py b/plugins/action/common/nac_dc_validate.py index ade0a690..3af8b48d 100644 --- a/plugins/action/common/nac_dc_validate.py +++ b/plugins/action/common/nac_dc_validate.py @@ -26,10 +26,17 @@ from ansible.utils.display import Display from ansible.plugins.action import ActionBase +from ansible.errors import AnsibleError + +try: + import iac_validate.validator + from iac_validate.yaml import load_yaml_files + from iac_validate.cli.options import DEFAULT_SCHEMA +except ImportError as imp_exc: + IAC_VALIDATE_IMPORT_ERROR = imp_exc +else: + IAC_VALIDATE_IMPORT_ERROR = None -import iac_validate.validator -from iac_validate.yaml import load_yaml_files -from iac_validate.cli.options import DEFAULT_SCHEMA import os display = Display() @@ -43,6 +50,9 @@ def run(self, tmp=None, task_vars=None): results['msg'] = None results['data'] = {} + if IAC_VALIDATE_IMPORT_ERROR: + raise AnsibleError('iac-validate not found and must be installed. Please pip install iac-validate.') from IAC_VALIDATE_IMPORT_ERROR + schema = self._task.args.get('schema') rules = self._task.args.get('rules') mdata = self._task.args.get('mdata')