66 lines
1.8 KiB
Python
66 lines
1.8 KiB
Python
|
"""Ansible Actions module."""
|
||
|
|
||
|
import click
|
||
|
from PyInquirer import prompt
|
||
|
|
||
|
from autonomic import logger
|
||
|
from autonomic.ansible import run_ansible_playbook
|
||
|
from autonomic.passstore import get_from_pass
|
||
|
from autonomic.settings import ACTIONS_PATH
|
||
|
|
||
|
log = logger.get_logger(__name__)
|
||
|
|
||
|
|
||
|
@click.command()
|
||
|
@click.pass_context
|
||
|
def actions(ctx):
|
||
|
"""Run an Ansible action."""
|
||
|
question = [
|
||
|
{
|
||
|
"type": "list",
|
||
|
"name": "action",
|
||
|
"message": "Which Ansible action do you want to run?",
|
||
|
"choices": [
|
||
|
{"name": "addusers"},
|
||
|
{"name": "newhetzner"},
|
||
|
{"name": "rmhetzner"},
|
||
|
{"name": "newdokku"},
|
||
|
],
|
||
|
"filter": lambda val: val.lower(),
|
||
|
}
|
||
|
]
|
||
|
action_answer = prompt(question)
|
||
|
|
||
|
env = {}
|
||
|
if (
|
||
|
action_answer["action"] == "newhetzner"
|
||
|
or action_answer["action"] == "rmhetzner"
|
||
|
):
|
||
|
question = [
|
||
|
{
|
||
|
"type": "list",
|
||
|
"name": "key",
|
||
|
"message": "Which Hetzner API key do you need?",
|
||
|
"choices": [
|
||
|
{"name": "prod"},
|
||
|
{"name": "test"},
|
||
|
{"name": "cicd"},
|
||
|
],
|
||
|
"filter": lambda val: val.lower(),
|
||
|
}
|
||
|
]
|
||
|
|
||
|
key_answer = prompt(question)
|
||
|
path = "logins/hetzner/{}/api_key".format(key_answer["key"])
|
||
|
secret = get_from_pass(path)
|
||
|
env["HCLOUD_TOKEN"] = secret
|
||
|
|
||
|
play = "{}/{}.yml".format(ACTIONS_PATH, action_answer["action"])
|
||
|
|
||
|
run_ansible_playbook(play, extra_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
|