cli: use env through ansible for ioc commands
Deploy / deploy (push) Canceled after 0s

This commit is contained in:
Benjamin Labrecque
2026-07-20 15:13:18 +02:00
parent 1d9946c22e
commit c4d6f2afb4
6 changed files with 108 additions and 20 deletions
+7 -2
View File
@@ -4,6 +4,7 @@ import sys
import ansible_runner
import typer
from core.enums import IOC_ENV
from core.utils import get_git_root
ioc = typer.Typer(no_args_is_help=True)
@@ -11,7 +12,11 @@ ioc = typer.Typer(no_args_is_help=True)
REPO_ROOT = get_git_root(__file__)
def run_playbook(playbook: str, vars: list[str]):
def run_playbook(playbook: str, env: IOC_ENV, vars: list[str]):
env_str = str(env)
if env_str not in ["dev", "prod"]:
raise ValueError("env must be 'dev' or 'prod'")
current_env = os.environ.copy()
current_env["ANSIBLE_CONFIG"] = f"{REPO_ROOT}/ansible/ansible.cfg"
@@ -21,7 +26,7 @@ def run_playbook(playbook: str, vars: list[str]):
cmdline_args=[
playbook,
"-i",
f"{REPO_ROOT}/ansible/hosts.yml",
f"{REPO_ROOT}/ansible/inventories/{env_str}/hosts.yml",
*extra_vars,
"-v",
],
+10 -1
View File
@@ -3,4 +3,13 @@ from enum import Enum
class ServiceStatus(str, Enum):
ACTIVE = "active"
DISABLED = "disabled"
DISABLED = "disabled"
class IOC_ENV(str, Enum):
PROD = "prod"
DEV = "dev"
def __str__(self) -> str:
return self.value