From e7ed329bd81c2273c03e94c93c9ce9c1d01cdc86 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Sat, 1 Apr 2017 04:53:28 +0200 Subject: Initial import --- opts.sh | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 opts.sh (limited to 'opts.sh') diff --git a/opts.sh b/opts.sh new file mode 100644 index 0000000..020fb44 --- /dev/null +++ b/opts.sh @@ -0,0 +1,117 @@ +#!/bin/bash + +inventory="inventories/testing.erb" +group="nodes" + +usage() { + cat << END +Usage: $0 [-i inventory] [-g group] [extra-args-to-ansible] + +Parameters: + inventory - specifies name of inventory to use (testing, staging, production) + group - specifies node group to use if role is considered in action + +Actions: + -h - show help and exit + + Initial system installation + all - full install, all the following steps in sequence: + local - configure local ssh client + prepare - perform all required pre-configuration before setting openshift + openshift - setup OpenShift cluster + configure - configures OpenShift cluster (Storage, Users, OpenVPN tunnels) + projects - installs configuration files and OpenShift resources for KaaS and other configured projects + + Scaling the cluster + nodes - complete action: prepares the nodes, scales up the cluster, and reconfigures storage + prepare - prepares the new nodes + openshift-nodes - scales OpenShift cluster (master scallability is not checked) + configure - Configures new nodes (Storage, Users, OpenVPN tunnels) + + Configuration of new resources, etc. + users - configure user roles & passwords + storage - reconfigure Gluster and OpenShift volumes + projects - reconfigures OpenShift resources if necessary + vpn - reconfigure VPN tunnels + certs - re-generate OpenShift x509 certificates + check - check current setup and report if any maintenace should be peformed + setup - executes specific configuration task from ands-openshift + Tasks: hostnames, users, ssh, storage, heketi + + Custom actions + playbook.yml - execute the specified playbook + role - generates temporary playbook and executes the role + +END + echo + [ -n "$1" ] && echo "Error: $1" + exit +} + +apply() { + export ANSIBLE_HOST_KEY_CHECKING=False + + [ -n "$1" ] || usage "No action specified" + + action=$1 + shift 1 + + if [ -f "$action" ]; then + playbook=$action + elif [ -d "roles/$action" ]; then + role=$action + else + usage "Role '$action' is not existing" + fi + + clean="" + if [ -z "$playbook" ]; then + echo "Executing a specific role '$role' on '$group'" + playbook="playbooks/tmp_role.yml" + clean="playbooks/tmp_role.*" + + cat < playbooks/tmp_role.yml +- name: Common setup procedures + hosts: $group + remote_user: root + roles: + - ands_facts + - $role +END + fi + + ansible-playbook --vault-password-file .vault-pass -i $inventory $playbook $@ + + if [ -n "$clean" ]; then + rm -rf "$clean" + fi + + return $? +} + +while getopts ":i:g:h" o; do + case "${o}" in + h) + usage + ;; + i) + inventory=${OPTARG} + [ -f $inventory ] || [ -f inventories/${inventory}.erb ] || usage "Specified inventory '$inventory' is not found" + [ -f $inventory ] || inventory=inventories/${inventory}.erb + ;; + g) + group=${OPTARG} + ;; + \?) + usage "Invalid option: -$OPTARG" + ;; + :) + usage "Option -$OPTARG requires an argument" + ;; + *) + usage + ;; + esac +done + +shift $((OPTIND-1)) -- cgit v1.2.3