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.
This commit is contained in:
Johannes Hahn 2024-02-09 14:43:34 +01:00 committed by Daniel Wozniak
parent 2b364c92e6
commit 1207030427

View file

@ -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)):