Guillaume Coré
2017-08-21 ce9ea2b4a0e92da1c72d2a588d24511a1210eb31
add wrapper.sh script

- README
- two examples of .rc file
4 files added
143 ■■■■■ changed files
scripts/README.adoc 40 ●●●●● patch | view | raw | blame | history
scripts/ansible-provisioner.rc.example 6 ●●●●● patch | view | raw | blame | history
scripts/ocp-workshop-3.5.rc.example 18 ●●●●● patch | view | raw | blame | history
scripts/wrapper.sh 79 ●●●●● patch | view | raw | blame | history
scripts/README.adoc
New file
@@ -0,0 +1,40 @@
= Wrapper script
This script is a wrapper for end-users, to run ansible_agnostic_deployer playbooks.
All the configuration regarding an environment can be set in a .rc file (bash syntax). The script takes the file as first arg. Here is an example:
.ocp-example.rc
----
GUID=testocp35
REGION=eu-central-1
KEYNAME=gucore
ENVTYPE=ocp-workshop
SOFTWARE_TO_DEPLOY=openshift
HOSTZONEID=Z3IHLWJZOU9SRT
ENVTYPE_ARGS=(
-e osrelease=3.5.5.31
-e "bastion_instance_type=t2.large"
-e "master_instance_type=c4.xlarge"
-e "infranode_instance_type=c4.4xlarge"
-e "node_instance_type=c4.4xlarge"
-e "nfs_instance_type=m3.large"
-e "subdomain_base_suffix=.example.opentlc.com"
-e "node_instance_count=1"
-e own_repo_path=http://admin.example.com/repos/ocp/3.5
-e repo_version=3.5
)
----
It has several possible actions as second arg:
. provision
. destroy
. stop
. start
.Example run
----
$ cd scripts
$ ./wrapper.sh ocp-workshop-3.5.rc provision
----
scripts/ansible-provisioner.rc.example
New file
@@ -0,0 +1,6 @@
GUID=testprovisioner
REGION=eu-central-1
KEYNAME=gucore
HOSTZONEID=Z3IHLWJZOU9SRT
ENVTYPE=ansible-provisioner
ENVTYPE_ARGS=()
scripts/ocp-workshop-3.5.rc.example
New file
@@ -0,0 +1,18 @@
GUID=testocp35
REGION=eu-central-1
KEYNAME=gucore
ENVTYPE=ocp-workshop
SOFTWARE_TO_DEPLOY=openshift
HOSTZONEID=Z3IHLWJZOU9SRT
ENVTYPE_ARGS=(
-e osrelease=3.5.5.31
-e "bastion_instance_type=t2.large"
-e "master_instance_type=c4.xlarge"
-e "infranode_instance_type=c4.4xlarge"
-e "node_instance_type=c4.4xlarge"
-e "nfs_instance_type=m3.large"
-e "subdomain_base_suffix=.example.opentlc.com"
-e "node_instance_count=1"
-e own_repo_path=http://admin.example.com/repos/ocp/3.5
-e repo_version=3.5
)
scripts/wrapper.sh
New file
@@ -0,0 +1,79 @@
#!/bin/bash
# wapper script to agnostic_ansible_deployer playbooks
if [ $# != 2 ]; then
    echo "2 args needed" >&2
    echo
    echo 'wapper script to agnostic_ansible_deployer playbooks'
    echo "./$0 RCFILE ACTION"
    echo 'args'
    echo '- RCFILE: to be sourced, containing needed env variables (especially envtype_args array)'
    echo '- ACTION: provision|destroy|stop|start'
    exit 2
fi
set -xe -o pipefail
. "$1"
if [ -z "${GUID}" ]; then
    echo "GUID is mandatory"
    exit 2
fi
REGION=${REGION:-us-east-1}
KEYNAME=${KEYNAME:-ocpkey}
ENVTYPE=${ENVTYPE:-generic-example}
CLOUDPROVIDER=${CLOUDPROVIDER:-ec2}
if [ "$CLOUDPROVIDER" = "ec2" ]; then
    if [ -z "${HOSTZONEID}" ]; then
        echo "HOSTZONEID vars are mandatory"
        exit 2
    fi
fi
INSTALL_IPA_CLIENT=${INSTALL_IPA_CLIENT:-false}
REPO_METHOD=${REPO_METHOD:-file}
SOFTWARE_TO_DEPLOY=${SOFTWARE_TO_DEPLOY:-none}
STACK_NAME=${ENVTYPE}-${GUID}
ORIG=$(cd $(dirname $0); cd ..; pwd)
DEPLOYER_REPO_PATH="${ORIG}/ansible"
case $2 in
    provision)
        ansible-playbook \
            ${DEPLOYER_REPO_PATH}/main.yml  \
            -i ${DEPLOYER_REPO_PATH}/inventory/${CLOUDPROVIDER}.py \
            -e "ANSIBLE_REPO_PATH=${DEPLOYER_REPO_PATH}" \
            -e "guid=${GUID}" \
            -e "env_type=${ENVTYPE}" \
            -e "key_name=${KEYNAME}" \
            -e "cloud_provider=${CLOUDPROVIDER}" \
            -e "aws_region=${REGION}" \
            -e "HostedZoneId=${HOSTZONEID}" \
            -e "install_ipa_client=${INSTALL_IPA_CLIENT}" \
            -e "software_to_deploy=${SOFTWARE_TO_DEPLOY}" \
            -e "repo_method=${REPO_METHOD}" \
            ${ENVTYPE_ARGS[@]}
        ;;
    destroy)
        ansible-playbook \
            ${DEPLOYER_REPO_PATH}/configs/${ENVTYPE}/destroy_env.yml \
            -i ${DEPLOYER_REPO_PATH}/inventory/${CLOUDPROVIDER}.py \
            -e "ANSIBLE_REPO_PATH=${DEPLOYER_REPO_PATH}" \
            -e "guid=${GUID}" \
            -e "env_type=${ENVTYPE}"  \
            -e "cloud_provider=${CLOUDPROVIDER}" \
            -e "aws_region=${REGION}"  \
            -e "HostedZoneId=${HOSTZONEID}"  \
            -e "key_name=${KEYNAME}"  \
        ;;
    stop)
        aws ec2 stop-instances --region $REGION --instance-ids $(aws ec2 describe-instances --filters "Name=tag:aws:cloudformation:stack-name,Values=${STACK_NAME}" --query Reservations[*].Instances[*].InstanceId --region $REGION --output text)
        ;;
    start)
        aws ec2 start-instances --region $REGION --instance-ids `aws ec2 describe-instances --filters "Name=tag:aws:cloudformation:stack-name,Values=${STACK_NAME}" --query Reservations[*].Instances[*].InstanceId --region $REGION --output text`
        ;;
esac