Commit 5461fc0f by John Jarvis

Merge pull request #1121 from edx/jarv/create-deployment-var-file

updating abbey to use a deployment.yml var file
parents 53822f61 a9e6d103
...@@ -48,11 +48,13 @@ def parse_args(): ...@@ -48,11 +48,13 @@ def parse_args():
parser.add_argument('--noop', action='store_true', parser.add_argument('--noop', action='store_true',
help="don't actually run the cmds", help="don't actually run the cmds",
default=False) default=False)
parser.add_argument('--secure-vars', required=False, parser.add_argument('--secure-vars-file', required=False,
metavar="SECURE_VAR_FILE", metavar="SECURE_VAR_FILE", default=None,
help="path to secure-vars from the root of " help="path to secure-vars from the root of "
"the secure repo (defaults to ansible/" "the secure repo. By default <deployment>.yml and "
"vars/ENVIRONMENT-DEPLOYMENT.yml)") "<environment>-<deployment>.yml will be used if they "
"exist in <secure-repo>/ansible/vars/. This secure file "
"will be used in addition to these if they exist.")
parser.add_argument('--stack-name', parser.add_argument('--stack-name',
help="defaults to ENVIRONMENT-DEPLOYMENT", help="defaults to ENVIRONMENT-DEPLOYMENT",
metavar="STACK_NAME", metavar="STACK_NAME",
...@@ -151,6 +153,7 @@ def get_instance_sec_group(vpc_id): ...@@ -151,6 +153,7 @@ def get_instance_sec_group(vpc_id):
return grp_details[0].id return grp_details[0].id
def get_blessed_ami(): def get_blessed_ami():
images = ec2.get_all_images( images = ec2.get_all_images(
filters={ filters={
...@@ -167,6 +170,7 @@ def get_blessed_ami(): ...@@ -167,6 +170,7 @@ def get_blessed_ami():
return images[0].id return images[0].id
def create_instance_args(): def create_instance_args():
""" """
Looks up security group, subnet Looks up security group, subnet
...@@ -219,7 +223,9 @@ git_repo_secure="{configuration_secure_repo}" ...@@ -219,7 +223,9 @@ git_repo_secure="{configuration_secure_repo}"
git_repo_secure_name="{configuration_secure_repo_basename}" git_repo_secure_name="{configuration_secure_repo_basename}"
git_repo_private="{configuration_private_repo}" git_repo_private="{configuration_private_repo}"
git_repo_private_name=$(basename $git_repo_private .git) git_repo_private_name=$(basename $git_repo_private .git)
secure_vars_file="$base_dir/$git_repo_secure_name/{secure_vars}" secure_vars_file={secure_vars_file}
environment_deployment_secure_vars="$base_dir/$git_repo_secure_name/ansible/vars/{environment}-{deployment}.yml"
deployment_secure_vars="$base_dir/$git_repo_secure_name/ansible/vars/{deployment}.yml"
instance_id=\\ instance_id=\\
$(curl http://169.254.169.254/latest/meta-data/instance-id 2>/dev/null) $(curl http://169.254.169.254/latest/meta-data/instance-id 2>/dev/null)
instance_ip=\\ instance_ip=\\
...@@ -317,8 +323,22 @@ sudo pip install -r requirements.txt ...@@ -317,8 +323,22 @@ sudo pip install -r requirements.txt
cd $playbook_dir cd $playbook_dir
ansible-playbook -vvvv -c local -i "localhost," $play.yml -e@$secure_vars_file -e@$extra_vars if [[ -r "$deployment_secure_vars" ]]; then
ansible-playbook -vvvv -c local -i "localhost," stop_all_edx_services.yml -e@$secure_vars_file -e@$extra_vars extra_args_opts+=" -e@$deployment_secure_vars"
fi
if [[ -r "$environment_deployment_secure_vars" ]]; then
extra_args_opts+=" -e@$environment_deployment_secure_vars"
fi
if $secure_vars_file; then
extra_args_opts+=" -e@$secure_vars_file"
fi
extra_args_opts+=" -e@$extra_vars"
ansible-playbook -vvvv -c local -i "localhost," $play.yml $extra_args_opts
ansible-playbook -vvvv -c local -i "localhost," stop_all_edx_services.yml $extra_args_opts
rm -rf $base_dir rm -rf $base_dir
...@@ -339,7 +359,7 @@ rm -rf $base_dir ...@@ -339,7 +359,7 @@ rm -rf $base_dir
queue_name=run_id, queue_name=run_id,
extra_vars_yml=extra_vars_yml, extra_vars_yml=extra_vars_yml,
git_refs_yml=git_refs_yml, git_refs_yml=git_refs_yml,
secure_vars=secure_vars, secure_vars_file=secure_vars_file,
cache_id=args.cache_id) cache_id=args.cache_id)
mapping = BlockDeviceMapping() mapping = BlockDeviceMapping()
...@@ -524,6 +544,7 @@ def create_ami(instance_id, name, description): ...@@ -524,6 +544,7 @@ def create_ami(instance_id, name, description):
return image_id return image_id
def launch_and_configure(ec2_args): def launch_and_configure(ec2_args):
""" """
Creates an sqs queue, launches an ec2 instance, Creates an sqs queue, launches an ec2 instance,
...@@ -613,13 +634,14 @@ def launch_and_configure(ec2_args): ...@@ -613,13 +634,14 @@ def launch_and_configure(ec2_args):
return run_summary, ami return run_summary, ami
def send_hipchat_message(message): def send_hipchat_message(message):
#If hipchat is configured send the details to the specified room #If hipchat is configured send the details to the specified room
if args.hipchat_api_token and args.hipchat_room_id: if args.hipchat_api_token and args.hipchat_room_id:
import hipchat import hipchat
try: try:
hipchat = hipchat.HipChat(token=args.hipchat_api_token) hipchat = hipchat.HipChat(token=args.hipchat_api_token)
hipchat.message_room(args.hipchat_room_id,'AbbeyNormal', hipchat.message_room(args.hipchat_room_id, 'AbbeyNormal',
message) message)
except Exception as e: except Exception as e:
print("Hipchat messaging resulted in an error: %s." % e) print("Hipchat messaging resulted in an error: %s." % e)
...@@ -648,11 +670,13 @@ if __name__ == '__main__': ...@@ -648,11 +670,13 @@ if __name__ == '__main__':
git_refs_yml = "" git_refs_yml = ""
git_refs = {} git_refs = {}
if args.secure_vars: if args.secure_vars_file:
secure_vars = args.secure_vars # explicit path to a single
# secure var file
secure_vars_file = args.secure_vars_file
else: else:
secure_vars = "ansible/vars/{}-{}.yml".format( secure_vars_file = 'false'
args.environment, args.deployment)
if args.stack_name: if args.stack_name:
stack_name = args.stack_name stack_name = args.stack_name
else: else:
...@@ -694,8 +718,7 @@ if __name__ == '__main__': ...@@ -694,8 +718,7 @@ if __name__ == '__main__':
run[0], run[1] / 60, run[1] % 60) run[0], run[1] / 60, run[1] % 60)
print "AMI: {}".format(ami) print "AMI: {}".format(ami)
message = 'Finished baking AMI {image_id} for {environment} ' \ message = 'Finished baking AMI {image_id} for {environment} {deployment} {play}.'.format(
'{deployment} {play}.'.format(
image_id=ami, image_id=ami,
environment=args.environment, environment=args.environment,
deployment=args.deployment, deployment=args.deployment,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment