#!/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 gluster - configure gluster software and volumes 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 (after ands_facts) 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 if [[ "$action" == anslib/* ]]; then echo "Executing a library playbook '$action'" cat < playbooks/tmp_play.yml - name: Common setup procedures hosts: $group remote_user: root roles: - ands_facts - import_playbook: ../$action END playbook="playbooks/tmp_play.yml" clean="playbooks/tmp_play.*" else playbook=$action fi 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 -vvv --vault-password-file .vault-pass -i $inventory $playbook $@ 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))