amiibofindr/deploy.py

50 lines
1.2 KiB
Python
Raw Normal View History

2015-06-15 20:17:07 +00:00
# coding: utf-8
# 3rd party
import click
from fabric.api import local
@click.command()
2015-06-16 21:40:53 +00:00
@click.option('--branch', '-b', default='master',
2015-06-15 20:17:07 +00:00
help='Branch to git clone from')
@click.option('--inventory', '-i', default='hosts',
help='Inventory file for ansible to use')
2015-09-10 20:54:16 +00:00
@click.option('--host', '-h', default='web-01',
2015-06-15 20:17:07 +00:00
help='Host to deploy to')
@click.option('--tag', '-t', default='deploy',
help='Ansible tags to run')
@click.option('--tasks', count=True,
help='List tasks instead of executing them')
@click.option('--hosts', count=True,
help='List hosts instead of executing tasks')
@click.option('--verbose', count=True,
help='Appends -vvvv to ansible')
def deploy(branch, inventory, host, tag, tasks, hosts, verbose):
cmd = 'ansible-playbook -i provision/{}'.format(inventory)
if host:
cmd += ' -l {}'.format(host)
cmd += ' -t {}'.format(tag)
if tasks:
cmd += ' --list-tasks'
if hosts:
cmd += ' --list-hosts'
cmd += ' -e git_branch={}'.format(branch)
cmd += ' provision/playbook.yml'
if verbose:
cmd += ' -vvvv'
local(cmd)
# Let's do this
if __name__ == '__main__':
deploy()