From 7ae6de3c5dcc224adbae1c6256ec53404b326974 Mon Sep 17 00:00:00 2001 From: Carlos Segarra Date: Thu, 22 Aug 2024 16:35:57 +0000 Subject: [PATCH] vm: add --env flag to run-comand --- tasks/vm.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tasks/vm.py b/tasks/vm.py index fa67763..c107ba7 100644 --- a/tasks/vm.py +++ b/tasks/vm.py @@ -236,14 +236,23 @@ def ssh(ctx, name): ) -@task -def run_command(ctx, name, path, cmd): +@task(iterable=["env"]) +def run_command(ctx, name, path, cmd, env=None): """ Run a command on the remote VM """ ip_addr = _get_ip(name) cmd_base = _build_ssh_command(ip_addr) - cmd = "{} \"bash -c 'cd {} && {}'\"".format(cmd_base, path, cmd) + + env_var_str = "" + if env is not None: + env_var_list = [env_var for env_var in env] + env_var_str = " ".join(env_var_list) + env_var_str += " &&" + + cmd = "{} \"bash -c '{}cd {} && {}'\"".format( + cmd_base, env_var_str, path, cmd + ) print(cmd) run(cmd, shell=True, check=True)