def add_user_to_docker_group(self): """ Make sure the ubuntu user is part of the docker group. """ log_green('adding the ubuntu user to the docker group') data = load_state_from_disk() with settings(hide('warnings', 'running', 'stdout', 'stderr'), warn_only=True, capture=True): user_ensure('ubuntu', home='/home/ubuntu', shell='/bin/bash') group_ensure('docker', gid=55) group_user_ensure('docker', 'ubuntu')
def up(): """ Boots a new Ubuntu instance on AWS, or start the existing instance. """ if is_there_state(): data = load_state_from_disk() cloud_type = data['cloud_type'] username = data['username'] distribution = data['distribution'] + data['os_release']['VERSION_ID'] region = data['region'] access_key_id = cloud_config['access_key_id'] secret_access_key = cloud_config['secret_access_key'] instance_id = data['id'] env.user = data['username'] env.key_filename = cloud_config['key_filename'] ec2() f_up(cloud=cloud_type, region=region, instance_id=instance_id, access_key_id=access_key_id, secret_access_key=secret_access_key, username=username) else: env.user = cloud_config['username'] env.key_filename = cloud_config['key_filename'] # no state file around, lets create a new VM # and use defaults values we have in our 'cloud_config' dictionary create_server(cloud='ec2', region=cloud_config['region'], access_key_id=cloud_config['access_key_id'], secret_access_key=cloud_config[ 'secret_access_key'], distribution='ubuntu14.04', disk_name=cloud_config['disk_name'], disk_size=cloud_config['disk_size'], ami=cloud_config['ami'], key_pair=cloud_config['key_pair'], instance_type=cloud_config['instance_type'], instance_name=cloud_config['instance_name'], username=cloud_config['username'], security_groups=cloud_config[ 'security_groups'], tags=cloud_config['tags'])
def destroy(): """ Destroy an existing instance. """ data = load_state_from_disk() cloud_type = data['cloud_type'] distribution = data['distribution'] + data['os_release']['VERSION_ID'] region = data['region'] access_key_id = cloud_config['access_key_id'] secret_access_key = cloud_config['secret_access_key'] instance_id = data['id'] env.user = data['username'] env.key_filename = cloud_config['key_filename'] f_destroy(cloud=cloud_type, region=region, instance_id=instance_id, access_key_id=access_key_id, secret_access_key=secret_access_key)
def down(): """ Halt an existing instance. """ data = load_state_from_disk() region = data['region'] cloud_type = data['cloud_type'] distribution = data['distribution'] + data['os_release']['VERSION_ID'] access_key_id = cloud_config['access_key_id'] secret_access_key = cloud_config['secret_access_key'] instance_id = data['id'] env.key_filename = cloud_config['key_filename'] ec2() f_down(cloud=cloud_type, instance_id=instance_id, region=region, access_key_id=access_key_id, secret_access_key=secret_access_key)
security_groups=cloud_config[ 'security_groups'], tags=cloud_config['tags']) @task def it(): execute(up) execute(bootstrap) @task def bootstrap(): cookbook = GithubPRHandlerCookbook() cookbook.install_packages() cookbook.start_github_handler_instance() # Modify some global Fabric behaviours: # Let's disable known_hosts, since on Clouds that behaviour can get in the # way as we continuosly destroy/create boxes. env.disable_known_hosts = True env.use_ssh_config = False env.eagerly_disconnect = True env.connection_attemtps = 5 env.user = '******' if is_there_state(): data = load_state_from_disk() env.hosts = data['ip_address'] env.cloud = data['cloud_type']