Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue 346 transformed playbook.py into script instead of TDP cli #481

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scripts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright 2022 TOSIT.IO
# SPDX-License-Identifier: Apache-2.0
27 changes: 23 additions & 4 deletions tdp/cli/commands/playbooks.py → scripts/playbooks.py
100644 → 100755
SteBaum marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -91,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")
Expand All @@ -103,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")
Expand All @@ -116,7 +131,11 @@ 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")


if __name__ == "__main__":
playbooks()
2 changes: 0 additions & 2 deletions tdp/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 0 additions & 15 deletions tdp/cli/commands/test_playbooks.py

This file was deleted.

Loading