From 34bc3d9e18487749d8d27092b60e6b61185f451d Mon Sep 17 00:00:00 2001 From: SteBaum Date: Thu, 26 Oct 2023 10:16:10 +0200 Subject: [PATCH 1/2] feat: transformed playbook.py into script instead of tdp-lib command --- scripts/__init__.py | 2 ++ {tdp/cli/commands => scripts}/playbooks.py | 19 ++++++++++++++++++- tdp/cli/__main__.py | 2 -- tdp/cli/commands/test_playbooks.py | 15 --------------- 4 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 scripts/__init__.py rename {tdp/cli/commands => scripts}/playbooks.py (86%) mode change 100644 => 100755 delete mode 100644 tdp/cli/commands/test_playbooks.py diff --git a/scripts/__init__.py b/scripts/__init__.py new file mode 100644 index 00000000..821e8433 --- /dev/null +++ b/scripts/__init__.py @@ -0,0 +1,2 @@ +# Copyright 2022 TOSIT.IO +# SPDX-License-Identifier: Apache-2.0 diff --git a/tdp/cli/commands/playbooks.py b/scripts/playbooks.py old mode 100644 new mode 100755 similarity index 86% rename from tdp/cli/commands/playbooks.py rename to scripts/playbooks.py index 9151f00d..348f592b --- a/tdp/cli/commands/playbooks.py +++ b/scripts/playbooks.py @@ -1,6 +1,20 @@ # Copyright 2022 TOSIT.IO # SPDX-License-Identifier: Apache-2.0 +""" +Generate meta playbooks in order to use a TDP like collection without tdp-lib. + +It checks the ansible playbooks which are given as input and returns a meta folder with the following yaml files: + +- all_per_service.yml listing all service. +- all.yml listing the location of all yaml files of every service. +- yaml file for each specified service containing the location of every yaml file concerning this service. + +The command `python path/to/playbooks.py` will execute the script with all collections defined in the `TDP_COLLECTION_PATH` including every service. + +Use the `-h` or `--help` option to get further information about the options. +""" + from pathlib import Path import click @@ -11,7 +25,6 @@ from tdp.core.operation import Operation -# TODO: Transform this to a script as it is not really a command (see #346). @click.command() @click.argument("services", required=False, nargs=-1) @click.option( @@ -120,3 +133,7 @@ def write_copyright_licence_headers(fd): ) else: all_fd.write(f"# {operation.name}\n") + + +if __name__ == "__main__": + playbooks() diff --git a/tdp/cli/__main__.py b/tdp/cli/__main__.py index 3ee50e1c..17555521 100644 --- a/tdp/cli/__main__.py +++ b/tdp/cli/__main__.py @@ -15,7 +15,6 @@ from tdp.cli.commands.init import init from tdp.cli.commands.ops import ops from tdp.cli.commands.plan import plan -from tdp.cli.commands.playbooks import playbooks from tdp.cli.commands.status import status from tdp.cli.commands.validate import validate from tdp.cli.commands.vars import vars @@ -65,7 +64,6 @@ def main(): cli.add_command(init) cli.add_command(ops) cli.add_command(plan) - cli.add_command(playbooks) cli.add_command(status) cli.add_command(validate) cli.add_command(vars) diff --git a/tdp/cli/commands/test_playbooks.py b/tdp/cli/commands/test_playbooks.py deleted file mode 100644 index dd12cb9c..00000000 --- a/tdp/cli/commands/test_playbooks.py +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright 2022 TOSIT.IO -# SPDX-License-Identifier: Apache-2.0 - -from pathlib import Path - -from click.testing import CliRunner - -from tdp.cli.commands.playbooks import playbooks - - -def test_tdp_playbooks(collection_path: Path, tmp_path: Path): - args = ["--collection-path", collection_path, "--output-dir", tmp_path] - runner = CliRunner() - result = runner.invoke(playbooks, args) - assert result.exit_code == 0, result.output From 751d92ec624dc8317a4a0fb060ff205dc60eea8a Mon Sep 17 00:00:00 2001 From: SteBaum Date: Wed, 6 Dec 2023 19:39:24 +0100 Subject: [PATCH 2/2] refactor: changed import_playbook with ansible.builtin.import_playbook --- scripts/playbooks.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/playbooks.py b/scripts/playbooks.py index 348f592b..0184dfca 100755 --- a/scripts/playbooks.py +++ b/scripts/playbooks.py @@ -104,7 +104,9 @@ def write_copyright_licence_headers(fd): if all(map(is_noop, dag_service_operations[service])): all_per_service_fd.write(f"# {service}\n") continue - all_per_service_fd.write(f"- import_playbook: {service}.yml\n") + all_per_service_fd.write( + f"- ansible.builtin.import_playbook: {service}.yml\n" + ) with Path(meta_dir, f"{service}.yml").open("w") as service_fd: write_copyright_licence_headers(service_fd) service_fd.write("---\n") @@ -116,7 +118,7 @@ def write_copyright_licence_headers(fd): continue if not operation.noop: service_fd.write( - f"- import_playbook: {playbooks_prefix}{operation.name}.yml\n" + f"- ansible.builtin.import_playbook: {playbooks_prefix}{operation.name}.yml\n" ) else: service_fd.write(f"# {operation.name}\n") @@ -129,7 +131,7 @@ def write_copyright_licence_headers(fd): continue if not operation.noop: all_fd.write( - f"- import_playbook: {playbooks_prefix}{operation.name}.yml\n" + f"- ansible.builtin.import_playbook: {playbooks_prefix}{operation.name}.yml\n" ) else: all_fd.write(f"# {operation.name}\n")