diff --git a/tdp/cli/__main__.py b/tdp/cli/__main__.py index 4ed44822..d50acb97 100644 --- a/tdp/cli/__main__.py +++ b/tdp/cli/__main__.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 import logging +from os import chdir from pathlib import Path from typing import Optional @@ -50,6 +51,15 @@ def load_env(ctx: click.Context, param: click.Parameter, value: Path) -> Optiona type=click.Choice(["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]), help="Set the level of log output.", ) +@click.option( + "--run-directory", + envvar="TDP_RUN_DIRECTORY", + type=click.Path(resolve_path=True, exists=True), + help="Working directory where the executor is launched (`ansible-playbook` for Ansible).", + required=True, + callback=lambda ctx, param, value: chdir(value), + expose_value=False, +) def cli(log_level: str): setup_logging(log_level) logging.info("Logging is configured.") diff --git a/tdp/cli/commands/deploy.py b/tdp/cli/commands/deploy.py index 2d582023..b61b277f 100644 --- a/tdp/cli/commands/deploy.py +++ b/tdp/cli/commands/deploy.py @@ -42,13 +42,6 @@ is_flag=True, help="Mock the deploy, do not actually run the ansible playbook.", ) -@click.option( - "--run-directory", - envvar="TDP_RUN_DIRECTORY", - type=click.Path(resolve_path=True, path_type=Path, exists=True), - help="Working directory where the executor is launched (`ansible-playbook` for Ansible).", - required=True, -) @validate_option @vars_option def deploy( @@ -57,7 +50,6 @@ def deploy( db_engine: Engine, force_stale_update: bool, mock_deploy: bool, - run_directory: Path, validate: bool, vars: Path, ): @@ -77,7 +69,6 @@ def deploy( deployment_iterator = DeploymentRunner( collections=collections, executor=Executor( - run_directory=run_directory.absolute() if run_directory else None, dry=dry or mock_deploy, ), cluster_variables=cluster_variables, diff --git a/tdp/core/deployment/executor.py b/tdp/core/deployment/executor.py index ae6a54db..3138fa4a 100644 --- a/tdp/core/deployment/executor.py +++ b/tdp/core/deployment/executor.py @@ -28,7 +28,6 @@ def __init__(self, run_directory=None, dry: bool = False): ExecutableNotFoundError: If the ansible-playbook command is not found in PATH. """ # TODO configurable via config file - self._rundir = run_directory self._dry = dry # Resolve ansible-playbook command @@ -57,7 +56,6 @@ def _execute_ansible_command( command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, - cwd=self._rundir, universal_newlines=True, ) if res.stdout is None: