"""Actions module.""" from os import environ import click from PyInquirer import prompt from autonomic.config import ACTIONS_DIR from autonomic.infra import get_passwd, run_play from autonomic.utils import qlist @click.command() @click.pass_context def actions(ctx): """Run an Ansible action.""" choices = ["addusers", "newhetzner", "rmhetzner", "newdokku"] question = qlist("action", "Which Ansible action?", choices,) action = prompt(question)["action"] if action in any(("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 = environ.copy() env["HCLOUD_TOKEN"] = secret play = "{}/{}.yml".format(ACTIONS_DIR, action) run_play(play, env=env) # TODO(decentral1se): # git commit and push on infrastructure if we: # 1. ran an action that adds something new to the pass store # 2. added another machine to the inventory