Commit ea57ad51 by arbabnazar

added the termination date and time as motd

added the edx-sandbox role

Added the ddx-sandbox role and delete the previously added task from
the common role and add it to this separate role

take the date & time from tag

add the full template path

Add the exception handling

modified the motd script

modified the motd script

modified the motd script
parent de229682
......@@ -60,6 +60,7 @@
roles:
# rerun common to set the hostname, nginx to set basic auth
- common
- edx-sandbox
- role: nginx
nginx_sites:
- cms
......
---
#
# edX Configuration
#
# github: https://github.com/edx/configuration
# wiki: https://github.com/edx/configuration/wiki
# code style: https://github.com/edx/configuration/wiki/Ansible-Coding-Conventions
# license: https://github.com/edx/configuration/blob/master/LICENSE.TXT
#
#
#
# Tasks for role edx-sandbox
#
# Overview:
# This role will be use to copy the motd to the sandbox in order to
# show the sandbox termination time as motd
#
# Dependencies:
# This role will only work on edx sandbox
#
# Example play:
#
#
- name: update the termination date and time as motd
template: >
dest=/etc/update-motd.d/999-terminate-sandbox
src=etc/update-motd.d/temiate_motd.j2 mode=0755 owner=root group=root
#!/usr/bin/python
import boto
from boto.utils import get_instance_metadata
from datetime import timedelta
from datetime import datetime
ec2 = boto.connect_ec2()
instance_id = get_instance_metadata()['instance-id']
reservations = ec2.get_all_instances(instance_ids=[instance_id])
instance = reservations[0].instances[0]
if instance.tags.has_key('instance_termination_time'):
terminate_time = datetime.strptime(str(instance.tags['instance_termination_time']), "%m-%d-%Y %H:%M:%S")
else:
terminate_time = datetime.strptime(instance.launch_time, "%Y-%m-%dT%H:%M:%S.%fZ") + timedelta(days=7)
print('This system will be terminated on {:%b %d, %Y}'.format(terminate_time))
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