Skip to content
Snippets Groups Projects
Commit 74f06289 authored by jurgenhaas's avatar jurgenhaas
Browse files

Replace shell scripts with python scripts

parent 82053a3a
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python
'''
Wrapper for the official Ansible Playbook application
=====================================================
'''
import os
import argparse
from subprocess import call
def callAnsible(playbook, inventory, args):
cmd = ['ansible-playbook', playbook + '.yml', '-i', inventory]
for arg in args:
cmd.append(arg)
call(cmd, cwd=path)
parser = argparse.ArgumentParser(description='Ansible Playbook wrapper by Paragon')
parser.add_argument('playbook',
help='Playbook to execute')
parser.add_argument('--local', action='store_true', default=False,
help='Set to true to work with the localhost only')
parser.add_argument('--custom', action='store_true', default=False,
help='Set to true to only execute playbook in the inventory directory')
args, extras = parser.parse_known_args()
path = os.path.dirname(os.path.realpath(__file__)) + '/'
pathSecrets = os.path.realpath(os.environ['HOME']) + '/.ansible/secrets'
pathCustom = path
# Start building command
cmd = []
# Determine inventory file
if args.local:
inventory = path + 'local.inventory'
pathCustom = False
elif os.path.exists(path + 'inventory/inventory'):
inventory = path + 'inventory/inventory'
pathCustom = path + 'inventory/'
else:
inventory = path + 'inventory/' + os.environ['ANSIBLE_COMPANY'] + '/inventory'
pathCustom = path + 'inventory/' + os.environ['ANSIBLE_COMPANY'] + '/'
if not os.path.exists(inventory):
raise SystemError('Inventory %s not found' % inventory)
# Check for the vault
if os.path.exists(pathSecrets):
cmd.append('-e')
cmd.append('@' + pathSecrets)
else:
cmd.append('--ask-sudo-pass')
# Append more CLI options
for extra in extras:
cmd.append(extra)
# Run the main playbook if not in custom mode
if not args.custom:
callAnsible(args.playbook, inventory, cmd)
# Optionally also run the custom playbook
if pathCustom and os.path.exists(pathCustom + args.playbook + '.yml'):
callAnsible(pathCustom + args.playbook, inventory, cmd)
#!/bin/bash
if [ -d ~/.ansible ]
then
SECRETS="$( cd ~/.ansible && pwd )/secrets"
fi
cd $( cd $(dirname $(readlink -f $0)) ; pwd )
if [ $1 == "local" ]
then
CUSTOM_DIR=false
INVENTORY=./local.inventory
shift
else
if [ -f ./inventory/inventory ]
then
CUSTOM_DIR=./inventory
else
CUSTOM_DIR=./inventory/$ANSIBLE_COMPANY
fi
INVENTORY=$CUSTOM_DIR/inventory
fi
if [ "$1" == "" ]
then
echo "Usage"
echo "ansible-playbook.sh PLAYBOOK ..."
exit 101;
fi
if [ $1 == "custom" ]
then
shift
PLAYBOOK_PREFIX=$CUSTOM_DIR/
else
PLAYBOOK_PREFIX=""
fi
PLAYBOOK=$PLAYBOOK_PREFIX$1.yml
shift
if [ ! -f $INVENTORY ]
then
echo "The inventory $INVENTORY does not exist!"
exit 102;
fi
if [ ! -f $PLAYBOOK ]
then
echo "The playbook $PLAYBOOK does not exist!"
exit 103;
fi
if [ $SECRETS ] && [ -f $SECRETS ]
then
ansible-playbook $PLAYBOOK -i $INVENTORY -e @$SECRETS "$@"
else
ansible-playbook $PLAYBOOK -i $INVENTORY --ask-sudo-pass "$@"
fi
if [ $CUSTOM_DIR != "false" ] && [ "$CUSTOM_DIR" != "$PLAYBOOK_PREFIX" ] && [ -f $CUSTOM_DIR/$PLAYBOOK ]
then
if [ $SECRETS ] && [ -f $SECRETS ]
then
ansible-playbook $CUSTOM_DIR/$PLAYBOOK -i $INVENTORY -e @$SECRETS "$@"
else
ansible-playbook $CUSTOM_DIR/$PLAYBOOK -i $INVENTORY --ask-sudo-pass "$@"
fi
fi
#!/usr/bin/env python
'''
Wrapper for the official Ansible application
============================================
'''
import os
import argparse
from subprocess import call
parser = argparse.ArgumentParser(description='Ansible wrapper by Paragon')
parser.add_argument('host',
help='Host name or pattern')
args, extras = parser.parse_known_args()
path = os.path.dirname(os.path.realpath(__file__)) + os.path.sep
pathSecrets = os.path.realpath(os.environ['HOME']) + '/.ansible/secrets'
# Start building command
cmd = ['ansible', args.host]
# Determine inventory file
if os.path.exists(path + 'inventory/inventory'):
inventory = path + 'inventory/inventory'
else:
inventory = path + 'inventory/' + os.environ['ANSIBLE_COMPANY'] + '/inventory'
if not os.path.exists(inventory):
raise SystemError('Inventory %s not found' % inventory)
cmd.append('-i')
cmd.append(inventory)
# Check for the vault
if os.path.exists(pathSecrets):
cmd.append('-e')
cmd.append('@' + pathSecrets)
# Append more CLI options
for extra in extras:
cmd.append(extra)
call(cmd, cwd=path)
#!/bin/bash
if [ -d ~/.ansible ]
then
SECRETS="$( cd ~/.ansible && pwd )/secrets"
fi
cd $( cd $(dirname $(readlink -f $0)) ; pwd )
if [ -f ./inventory/inventory ]
then
INVENTORY=./inventory/inventory
else
INVENTORY=./inventory/$ANSIBLE_COMPANY/inventory
fi
if [ "$3" == "" ]
then
echo "Usage"
echo "ansible.sh HOSTS COMMAND OPTIONS"
exit 101;
fi
HOSTS=$1
shift
if [ ! -f $INVENTORY ]
then
echo "The inventory $INVENTORY does not exist!"
exit 102;
fi
if [ -f $SECRETS ]
then
ansible $HOSTS -i $INVENTORY -e @$SECRETS "$@"
else
ansible $HOSTS -i $INVENTORY "$@"
fi
role.py 0 → 100755
#!/usr/bin/env python
'''
Wrapper for the role playbook
=============================
'''
import os
import argparse
from subprocess import call
parser = argparse.ArgumentParser(description='Wrapper for the role playbook')
parser.add_argument('role',
help='Role to execute')
parser.add_argument('hosts',
help='Host name or pattern')
args, extras = parser.parse_known_args()
path = os.path.dirname(os.path.realpath(__file__)) + os.path.sep
# Start building command
cmd = [path + 'ansible-playbook.py', 'role', '--extra-vars=hosts=' + args.hosts + ' role=' + args.role]
# Append more CLI options
for extra in extras:
cmd.append(extra)
call(cmd, cwd=path)
#!/bin/bash
cd $( cd $(dirname $(readlink -f $0)) ; pwd )
if [ "$2" == "" ]
then
echo "Usage"
echo "role.sh HOSTS ROLE"
exit 101;
fi
HOSTS=$1
ROLE=$2
shift
shift
./ansible-playbook.sh role --extra-vars="hosts=$HOSTS role=$ROLE" "$@"
owncloud @ 8cb1b3c9
Subproject commit edb85ac71f98e6bb1a4f7b68780750a3b5a7563a
Subproject commit 8cb1b3c9fe0dba1a3cde4bd13e4891784e87da23
#!/usr/bin/env python
'''
Wrapper for the sanity playbook
===============================
'''
import os
import argparse
from subprocess import call
parser = argparse.ArgumentParser(description='Wrapper for the sanity playbook')
parser.add_argument('mode', choices=['check', 'upgrade', 'reboot'],
help='Mode for the sanity play')
args, extras = parser.parse_known_args()
path = os.path.dirname(os.path.realpath(__file__)) + os.path.sep
# Start building command
cmd = [path + 'ansible-playbook.py', 'sanity', '--tags=' + args.mode]
# Append more CLI options
for extra in extras:
cmd.append(extra)
call(cmd, cwd=path)
#!/bin/bash
cd $( cd $(dirname $(readlink -f $0)) ; pwd )
if [ "$1" == "" ]
then
echo "Usage"
echo "sanity.sh [check|upgrade|reboot]"
exit 101;
fi
TAGS=$1
shift
./ansible-playbook.sh sanity --tags="$TAGS" "$@"
......@@ -2,4 +2,4 @@
cd $( cd $(dirname $(realpath $0)) ; pwd )
./role.sh webserver-drupal drush --tags="DrushUpdateAliases" "$@"
../role.py drush webserver-drupal --tags="DrushUpdateAliases" "$@"
#!/usr/bin/env python
'''
Setup and update the Paragon wrapper for Ansible
================================================
'''
import os
import argparse
from subprocess import call
parser = argparse.ArgumentParser(description='Wrapper for the role playbook')
parser.add_argument('company',
help='Name of the company in lowercase to specify the inventory')
args, extras = parser.parse_known_args()
path = os.path.dirname(os.path.realpath(__file__)) + os.path.sep
# Start building command
cmd = [path + 'ansible-playbook.py', 'setup_local', '--local=True', '--extra-vars=company=' + args.company]
# Append more CLI options
for extra in extras:
cmd.append(extra)
call(cmd, cwd=path)
#!/bin/bash
cd $( cd $(dirname $(readlink -f $0)) ; pwd )
if [ "$1" == "" ]
then
echo "Usage"
echo "setup_local.sh COMPANY"
exit 101;
fi
COMPANY=$1
shift
./ansible-playbook.sh local setup_local --extra-vars="company=$COMPANY" "$@"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment