This repository has been archived on 2020-06-17. You can view files and clone it, but cannot push or open issues or pull requests.
autonomic/autonomic/command/actions.py

35 lines
980 B
Python

"""Actions module."""
from os import environ
import click
from PyInquirer import prompt
from autonomic.config import ACTIONS_DIR, INFRA_DIR
from autonomic.infra import get_passwd, run_play
from autonomic.utils import git_status, qlist
@click.command()
@click.pass_context
def actions(ctx):
"""Run an Ansible action."""
env = environ.copy()
choices = ["addusers", "newhetzner", "rmhetzner", "newdokku"]
question = qlist("action", "Which Ansible action?", choices,)
action = prompt(question)["action"]
if any(action in choice for choice in ["newhetzner", "rmhetzner"]):
choices = ["prod", "test", "cicd"]
question = qlist("key", "Which Hetzner API key?", choices)
key = prompt(question)["key"]
path = "logins/hetzner/{}/api_key".format(key)
secret = get_passwd(path)
env["HCLOUD_TOKEN"] = secret
play = "{}/{}.yml".format(ACTIONS_DIR, action)
run_play(play, env=env)
git_status(INFRA_DIR)