#!/usr/bin/env python
# -*- coding: utf-8 -*-

from fabric.api import parallel, run
from fabric.operations import sudo, put


@parallel
def install_curl():
    '''
    Installs curl
    '''
    sudo("apt-get -y install curl")


@parallel
def apt_update():
    '''
    Runs apt-get update and upgrade
    '''
    sudo('apt-get -y update')
    sudo('apt-get -y upgrade')


def install_gitpython():
    '''
    Installs gitpython and dependencies
    '''
    sudo('apt-get install git python-git')


@parallel
def bootstrap_salt():
    '''
    Uses the salt bootstrap script (from bootstrap.saltstack.org) to install a
    salt-minion and run it as a daemon
    '''
    run("curl -L http://bootstrap.saltstack.org | sudo sh")


@parallel
def copy_minion_config():
    put('salt/minion', '/etc/salt/minion', use_sudo=True)


@parallel
def copy_salt_state():
    put('salt/roots/salt', '/srv', use_sudo=True)
    put('salt/roots/pillar', '/srv', use_sudo=True)


@parallel
def restart_minion():
    '''
    Restart a salt minion
    '''
    sudo("service salt-minion restart")


@parallel
def fullstrap_minions():
    '''
    Install saltstack, set master, restart the salt-minion daemon
    $ fab fullstrap_minions:master=127.0.0.1
    '''
    apt_update()
    install_curl()
    install_gitpython()
    bootstrap_salt()
    copy_minion_config()
    copy_salt_state()
    restart_minion()
    sudo('apt-get -y install vim')  # Sneaking this in to make life better

@@ -40,16 +40,26 @@
 -8 -*-%0A%0A
+import os%0A
 from fab
@@ -87,16 +87,56 @@
 el, run%0A
+from fabric.contrib.files import append%0A
 from fab
@@ -521,16 +521,19 @@
 install 
+-y 
 git pyth
@@ -1116,24 +1116,470 @@
 restart%22)%0A%0A%0A
+@parallel%0Adef run_highstate():%0A    sudo(%22salt-call state.highstate%22)%0A%0A%0Adef _read_key_file(key_file):%0A    key_file = os.path.expanduser(key_file)%0A    if not key_file.endswith('pub'):%0A        raise RuntimeWarning('Trying to push non-public part of key pair')%0A    with open(key_file) as f:%0A        return f.read()%0A%0A%0Adef push_key(key_file='~/.ssh/id_rsa.pub'):%0A    key_text = _read_key_file(key_file)%0A    append('~/.ssh/authorized_keys', key_text)%0A%0A%0A
 @parallel%0Ade
@@ -1885,75 +1885,20 @@
     
-sudo('apt-get -y install vim')  # Sneaking this in to make life better
+run_highstate()
 %0A

Add more fabric commands