39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
"""Actions module."""
|
|
|
|
from os import environ
|
|
|
|
import click
|
|
|
|
from autonomic.config import ACTIONS_DIR, INFRA_DIR, PASS_STORE_DIR
|
|
from autonomic.infra import get_passwd, run_play
|
|
from autonomic.settings import get
|
|
from autonomic.utils import ensure_config_dir, git_status, question_ask
|
|
|
|
|
|
@click.command()
|
|
@click.pass_context
|
|
def actions(ctx):
|
|
"""Run an Ansible action."""
|
|
ensure_config_dir()
|
|
|
|
env = environ.copy()
|
|
|
|
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"]
|
|
action = question_ask("action", "Which Ansible action?", choices)
|
|
|
|
if any(action in choice for choice in ["newhetzner", "rmhetzner"]):
|
|
choices = ["prod", "test", "cicd"]
|
|
key = question_ask("key", "Which Hetzner API key?", choices)
|
|
|
|
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)
|