run-ansible.sh 1.7 KB
Newer Older
1 2 3 4 5 6 7
#!/usr/bin/env bash

# A simple wrapper to run ansible from Jenkins.
# This assumes that you will be running on one or more servers
# that are tagged with Name: <environment>-<deployment>-<play>

if [[
8 9 10 11 12 13 14
        -z $WORKSPACE           ||
        -z $environment_tag     ||
        -z $deployment_tag      ||
        -z $play_tag            ||
        -z $ansible_play        ||
        -z $elb_pre_post        ||
        -z $first_in            ||
15
        -z $serial_count
16 17 18 19 20 21 22 23
    ]]; then
    echo "Environment incorrect for this wrapper script"
    env
    exit 1
fi

cd $WORKSPACE/configuration/playbooks/edx-east

John Jarvis committed
24
ansible_extra_vars+=" -e serial_count=$serial_count -e elb_pre_post=$elb_pre_post"
25 26

if [ ! -z "$extra_vars" ]; then
John Jarvis committed
27 28 29
    for arg in $extra_vars; do
        ansible_extra_vars+=" -e $arg"
    done
30 31
fi

32 33 34 35
if [[ $run_migrations == "true" ]]; then
      ansible_extra_vars+=" -e migrate_db=yes"
fi

36 37 38 39
if [[ $check_mode == "true" ]]; then
      ansible_extra_vars+=" --check"
fi

40 41 42 43 44 45 46
if [[ ! -z "$run_on_single_ip" ]]; then
    ansible_limit+="$run_on_single_ip"
else
    if [[ $first_in == "true" ]]; then
        ansible_limit+="first_in_"
    fi
    ansible_limit+="tag_Name_${environment_tag}-${deployment_tag}-${play_tag}"
47
fi
e0d committed
48

49
if [[ ! -z "$task_tags" ]]; then
e0d committed
50 51 52
    ansible_task_tags+="--tags $task_tags"
fi

e0d committed
53 54 55 56 57 58
if [[ -z "$ssh_user" ]]; then
    ansible_ssh_user="ubuntu"
else
    ansible_ssh_user="${ssh_user}"
fi

John Jarvis committed
59
export PYTHONUNBUFFERED=1
60
env
e0d committed
61
ansible-playbook -v -D -u $ansible_ssh_user $ansible_play -i ./ec2.py $ansible_task_tags --limit $ansible_limit -e@"$WORKSPACE/configuration-secure/ansible/vars/${deployment_tag}.yml" -e@"$WORKSPACE/configuration-secure/ansible/vars/${environment_tag}-${deployment_tag}.yml" $ansible_extra_vars