This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
import ansible_runner
|
||||
import typer
|
||||
|
||||
from core.utils import get_git_root
|
||||
|
||||
ioc = typer.Typer(no_args_is_help=True)
|
||||
|
||||
REPO_ROOT = get_git_root(__file__)
|
||||
|
||||
|
||||
def run_playbook(playbook: str, vars: list[str]):
|
||||
current_env = os.environ.copy()
|
||||
current_env["ANSIBLE_CONFIG"] = f"{REPO_ROOT}/ansible/ansible.cfg"
|
||||
|
||||
extra_vars = [f"--extra-vars={var}" for var in vars]
|
||||
out, err, rc = ansible_runner.run_command(
|
||||
executable_cmd=f"ansible-playbook",
|
||||
cmdline_args=[
|
||||
playbook,
|
||||
"-i",
|
||||
f"{REPO_ROOT}/ansible/hosts.yml",
|
||||
*extra_vars,
|
||||
"-v",
|
||||
],
|
||||
envvars=current_env,
|
||||
input_fd=sys.stdin,
|
||||
output_fd=sys.stdout,
|
||||
error_fd=sys.stderr,
|
||||
)
|
||||
print("rc: {}".format(rc))
|
||||
print("out: {}".format(out))
|
||||
print("err: {}".format(err))
|
||||
@@ -0,0 +1,49 @@
|
||||
import sys
|
||||
|
||||
import ansible_runner
|
||||
import typer
|
||||
|
||||
from core.ansible import run_playbook
|
||||
from core.utils import get_git_root
|
||||
|
||||
ioc = typer.Typer(no_args_is_help=True)
|
||||
|
||||
REPO_ROOT = get_git_root(__file__)
|
||||
|
||||
ANSIBLE_PLAYBOOKS_DIR = REPO_ROOT / "ansible" / "playbooks"
|
||||
IOC_PLAYBOOK_INSTALL = ANSIBLE_PLAYBOOKS_DIR / "ioc-install.yml"
|
||||
IOC_PLAYBOOK_RESTART = ANSIBLE_PLAYBOOKS_DIR / "ioc-restart.yml"
|
||||
IOC_PLAYBOOK_START = ANSIBLE_PLAYBOOKS_DIR / "ioc-start.yml"
|
||||
|
||||
|
||||
@ioc.command(no_args_is_help=True)
|
||||
def install(
|
||||
env: str = typer.Option(..., "--env"),
|
||||
service_name_lower: str = typer.Option(..., "--service-name", "-s"),
|
||||
):
|
||||
env_var = f"agebd_env={env}"
|
||||
branch_var = f"branch_name=feature/add-service-{service_name_lower}"
|
||||
service_name_var = f"service_name_lower={service_name_lower}"
|
||||
|
||||
run_playbook(playbook=str(IOC_PLAYBOOK_INSTALL), vars=[env_var, branch_var, service_name_var])
|
||||
|
||||
|
||||
@ioc.command(no_args_is_help=True)
|
||||
def restart(
|
||||
env: str = typer.Option(..., "--env"),
|
||||
service_name_lower: str = typer.Option(..., "--service-name", "-s"),
|
||||
):
|
||||
env_var = f"agebd_env={env}"
|
||||
branch_var = f"branch_name=feature/add-service-{service_name_lower}"
|
||||
service_name_var = f"service_name_lower={service_name_lower}"
|
||||
|
||||
run_playbook(playbook=str(IOC_PLAYBOOK_RESTART), vars=[env_var, branch_var, service_name_var])
|
||||
|
||||
|
||||
@ioc.command(no_args_is_help=True)
|
||||
def start(
|
||||
ioc_port: int = typer.Option(..., "--port", "-p"),
|
||||
):
|
||||
ioc_port_var = f"ioc_port={ioc_port}"
|
||||
|
||||
run_playbook(playbook=str(IOC_PLAYBOOK_START), vars=[ioc_port_var])
|
||||
@@ -2,6 +2,7 @@ import logging
|
||||
|
||||
import typer
|
||||
|
||||
import ioc
|
||||
import service
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -9,6 +10,7 @@ logger = logging.getLogger(__name__)
|
||||
cli = typer.Typer(no_args_is_help=True, add_completion=False)
|
||||
|
||||
cli.add_typer(service.service, name="service")
|
||||
cli.add_typer(ioc.ioc, name="ioc")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user