#!/usr/bin/env ruby # Copyright 2015 Adaptavist.com Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require 'avst-cloud' require 'avst-cloud/aws_connection' require 'avst-cloud/aws_server' avst_cloud_base="#{File.expand_path("../../", __FILE__)}" # FILL IN YOUR AWS ACCOUNT DETAILS (Access Key ID and Secret Access Key), GIT REPO AND MAKE SURE # FILES IN files FOLDER HAS CORRECT CONTENT provider_user='' provider_pass='' region='eu-west-1' # Initiate connector object conn = AvstCloud::AwsConnection.new(provider_user, provider_pass, region) server_name = 'hostname1' flavour = nil # defaults to t2.micro hdd_device_path = nil # defaults to '/dev/sda1' ami_image_id = "ami-f0b11187" os = "ubuntu-14" key_name = 'admin' # key name, e.g. admin ssh_key = "path/to/your/admin.pem" # Full path to ssh key, e.g. /tmp/admin.pem subnet_id = '' # Your subnet security_group_ids = [''] # List of security groups ebs_size = nil # In GB availability_zone = 'eu-west-1c' server = conn.create_server(server_name, flavour, os, key_name, ssh_key, subnet_id, security_group_ids, ebs_size, hdd_device_path, ami_image_id, availability_zone) # server = conn.server(server_name, nil, ssh_key, os) # server.destroy # puts conn.server_status(server_name) # exit pre_upload_commands = [ "echo 'pre_upload_command was here' >> /tmp/pre_upload", ] custom_file_uploads = { "#{avst_cloud_base}/files/id_rsa" => "/tmp/.", "#{avst_cloud_base}/files/known_hosts" => "/tmp/." } # Uploading ssh keys to access git repo in provisioning stage, make sure you provide correct keys post_upload_commands = [ "mkdir /home/ubuntu/.ssh", "mv /tmp/id_rsa /home/ubuntu/.ssh/.", "mv /tmp/known_hosts /home/ubuntu/.ssh/.", "chmod 0600 /home/ubuntu/.ssh/known_hosts", "chmod 0600 /home/ubuntu/.ssh/id_rsa", "mkdir /var/opt/puppet", "chown ubuntu /var/opt/puppet", "apt-get update && apt-get install -o Dpkg::Options::='--force-confold' -f -y git puppet-common puppet" ] remote_server_debug = true debug_structured_log = false server.bootstrap(pre_upload_commands, custom_file_uploads, post_upload_commands, remote_server_debug, debug_structured_log, false) git = "ssh://git@you_repo.git" branch = "master" reference = nil # Tag # In this example we do not use puppet-runner, check doco puppet_runner = nil puppet_runner_prepare = nil avst_cloud_config_dir = nil download_dependencies_command = nil custom_provisioning_commands = ["echo 'done' >> /tmp/done", "echo 'done' >> /tmp/done1"] server_tmp_folder="/tmp/avst_cloud_tmp_#{Time.now.to_i}" destination_folder = nil # defaults to /var/opt/puppet server.provision(git, branch, server_tmp_folder, reference, custom_provisioning_commands, puppet_runner, puppet_runner_prepare, destination_folder, avst_cloud_config_dir, download_dependencies_command) # puts conn.server_status(server_name) # server.stop # puts conn.server_status(server_name) # server.start # custom_commands=nil # server_tmp_folder="/tmp/done" # server.post_provisioning_cleanup(custom_commands, os, remote_server_debug, server_tmp_folder) # server.destroy # puts conn.server_status(server_name)