From 12070304270e100acd74c752d1c796c623c3f896 Mon Sep 17 00:00:00 2001 From: Johannes Hahn Date: Fri, 9 Feb 2024 14:43:34 +0100 Subject: [PATCH] Discover .yml and .yaml files Allow for 'playbook_extension' to be either a string or a tuple and change the default behavior to discover both. --- salt/modules/ansiblegate.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/salt/modules/ansiblegate.py b/salt/modules/ansiblegate.py index 2f60a7444fb..f017d395e7d 100644 --- a/salt/modules/ansiblegate.py +++ b/salt/modules/ansiblegate.py @@ -502,7 +502,7 @@ def discover_playbooks( List of paths to discover playbooks from. :param playbook_extension: - File extension of playbooks file to search for. Default: "yml" + File extension(s) of playbook files to search for, can be a string or tuple of strings. Default: (".yml", ".yaml") :param hosts_filename: Filename of custom playbook inventory to search for. Default: "hosts" @@ -533,7 +533,7 @@ def discover_playbooks( ) if not playbook_extension: - playbook_extension = "yml" + playbook_extension = (".yml", ".yaml") if not hosts_filename: hosts_filename = "hosts" @@ -573,7 +573,7 @@ def _explore_path(path, playbook_extension, hosts_filename, syntax_check): # Check files in the given path for _f in os.listdir(path): _path = os.path.join(path, _f) - if os.path.isfile(_path) and _path.endswith("." + playbook_extension): + if os.path.isfile(_path) and _path.endswith(playbook_extension): ret[_f] = {"fullpath": _path} # Check for custom inventory file if os.path.isfile(os.path.join(path, hosts_filename)): @@ -584,9 +584,7 @@ def _explore_path(path, playbook_extension, hosts_filename, syntax_check): # Check files in the 1st level of subdirectories for _f2 in os.listdir(_path): _path2 = os.path.join(_path, _f2) - if os.path.isfile(_path2) and _path2.endswith( - "." + playbook_extension - ): + if os.path.isfile(_path2) and _path2.endswith(playbook_extension): ret[os.path.join(_f, _f2)] = {"fullpath": _path2} # Check for custom inventory file if os.path.isfile(os.path.join(_path, hosts_filename)):