2020-04-11 19:10:29 +00:00
|
|
|
"""Actions module."""
|
|
|
|
|
|
|
|
from os import environ
|
2020-04-10 23:45:53 +00:00
|
|
|
|
|
|
|
import click
|
2020-04-11 20:52:27 +00:00
|
|
|
from PyInquirer import prompt
|
2020-04-10 23:45:53 +00:00
|
|
|
|
2020-04-11 21:18:31 +00:00
|
|
|
from autonomic.config import ACTIONS_DIR, INFRA_DIR, PASS_STORE_DIR
|
2020-04-11 19:10:29 +00:00
|
|
|
from autonomic.infra import get_passwd, run_play
|
2020-04-11 21:18:31 +00:00
|
|
|
from autonomic.settings import get
|
2020-04-11 21:18:50 +00:00
|
|
|
from autonomic.utils import git_status, qlist
|
2020-04-10 23:45:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
@click.command()
|
|
|
|
@click.pass_context
|
|
|
|
def actions(ctx):
|
|
|
|
"""Run an Ansible action."""
|
2020-04-11 20:47:16 +00:00
|
|
|
env = environ.copy()
|
|
|
|
|
2020-04-11 21:18:31 +00:00
|
|
|
env.update({"ANSIBLE_USER": get("username")})
|
|
|
|
env.update({"REMOTE_USER": get("username")})
|
|
|
|
env.update({"PASSWORD_STORE_DIR": PASS_STORE_DIR})
|
|
|
|
|
|
|
|
choices = ["addusers", "newhetzner", "rmhetzner", "newdokku", "pingall"]
|
2020-04-11 19:10:29 +00:00
|
|
|
question = qlist("action", "Which Ansible action?", choices,)
|
|
|
|
action = prompt(question)["action"]
|
|
|
|
|
2020-04-11 21:07:09 +00:00
|
|
|
if any(action in choice for choice in ["newhetzner", "rmhetzner"]):
|
2020-04-11 19:10:29 +00:00
|
|
|
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)
|
2020-04-10 23:45:53 +00:00
|
|
|
env["HCLOUD_TOKEN"] = secret
|
|
|
|
|
2020-04-11 19:10:29 +00:00
|
|
|
play = "{}/{}.yml".format(ACTIONS_DIR, action)
|
|
|
|
run_play(play, env=env)
|
2020-04-11 20:52:27 +00:00
|
|
|
git_status(INFRA_DIR)
|