Allow interactive calls

This commit is contained in:
Luke Murphy 2020-04-11 23:07:20 +02:00
parent 9c692f2335
commit 58b09694df
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
2 changed files with 9 additions and 3 deletions

View File

@ -30,8 +30,9 @@ def run_play(play, env=None):
"""Run an Ansible playbook."""
if env is None:
env = environ.copy()
cmd = [".venv/bin/ansible-playbook", play]
run(cmd, cwd=INFRA_DIR, env=env)
run(cmd, cwd=INFRA_DIR, interactive=True, env=env)
def get_passwd(path):

View File

@ -8,7 +8,7 @@ things here.
"""
from os import chdir
from subprocess import check_output
from subprocess import check_output, call
from psutil import process_iter
@ -16,7 +16,7 @@ from autonomic.logger import log
from autonomic.yaml import yaml
def run(cmd, cwd=None, **kwargs):
def run(cmd, cwd=None, interactive=False, **kwargs):
"""Run a system command.
Please note, all **kwargs will be passed into the check_output command so
@ -27,7 +27,11 @@ def run(cmd, cwd=None, **kwargs):
if cwd:
chdir(cwd)
log.info("Changed directory to {}".format(cwd))
log.info("Running {}".format(" ".join(cmd)))
if interactive:
return call(cmd, **kwargs)
return check_output(cmd, **kwargs)
except Exception as exception:
msg = "{} failed! Saw {}".format(" ".join(cmd), str(exception))
@ -90,6 +94,7 @@ def git_status(fpath):
"""Check if Git reports changes to be committed."""
cmd = ["git", "status", "--porcelain"]
output = run(cmd, cwd=fpath)
if output is not None:
msg = "warning: git reports uncommitted changes in {}".format(fpath)
log.warning(msg)