From d7dac43a72ecb972c468652d45ce34eb05430e8b Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Sat, 27 Jun 2020 22:33:51 +0200 Subject: [PATCH] add custom modules auto-detection --- CHANGELOG.md | 8 ++------ ansiblelater/settings.py | 13 +++++++++++++ docs/content/configuration/defaults.md | 7 ++++--- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6732846..00b0a7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,2 @@ -* BUGFIX - * fix typo in argparse description -* INTERNAL - * add markdown linting to CI (markdownlint-cli) - * add spellchecking to CI (spellcheck-cli) - * add broken link check to CI (broken-link-checker) +* ENHANCEMENT + * add custom modules auto-detection diff --git a/ansiblelater/settings.py b/ansiblelater/settings.py index 7a8f797..756430f 100644 --- a/ansiblelater/settings.py +++ b/ansiblelater/settings.py @@ -88,6 +88,19 @@ class Settings(object): if cli_options and self._validate(cli_options): anyconfig.merge(defaults, cli_options, ac_merge=anyconfig.MS_DICTS) + library = os.path.relpath(os.path.normpath(os.path.join(os.getcwd(), "library"))) + autodetect = [] + if os.path.exists(library): + autodetect = [ + os.path.splitext(f)[0] + for f in os.listdir(library) + if os.path.isfile(os.path.join(library, f)) and not f.startswith(".") + ] + + for f in autodetect: + if f not in defaults["ansible"]["custom_modules"]: + defaults["ansible"]["custom_modules"].append(f) + return defaults def _get_defaults(self): diff --git a/docs/content/configuration/defaults.md b/docs/content/configuration/defaults.md index e839f55..198d077 100644 --- a/docs/content/configuration/defaults.md +++ b/docs/content/configuration/defaults.md @@ -8,9 +8,10 @@ title: Default settings {{< highlight YAML "linenos=table" >}} --- ansible: - # Add the name of used custom Ansible modules. - # Otherwise ansible-later can't detect unknown modules - # and will through an error. + # Add the name of used custom Ansible modules. Otherwise ansible-later + # can't detect unknown modules and will through an error. + # Modules which are bundled with the role and placed in a './library' + # directory will be auto-detected and don't need to be added to this list. custom_modules: [] # Settings for variable formatting rule (ANSIBLE0004) double-braces: