#!/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/rackspace_connection' require 'avst-cloud/rackspace_server' avst_cloud_base="#{File.expand_path("../../", __FILE__)}" # FILL IN YOUR Rackspace ACCOUNT DETAILS (Username and Secret Access Key), GIT REPO, image_id AND MAKE SURE # FILES IN files FOLDER HAS CORRECT CONTENT provider_user='' provider_pass='' region=:lon # Initiate connector object conn = AvstCloud::RackspaceConnection.new(provider_user, provider_pass, region) server_name = 'hostname1' flavour = '4' image_id = '' # Please provide server = conn.create_server(server_name, image_id) puts conn.server_status(server_name) # server = conn.server(server_name, 'root', pass) 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 /root/.ssh", "mv /tmp/id_rsa /root/.ssh/.", "mv /tmp/known_hosts /root/.ssh/.", "chmod 0600 /root/.ssh/known_hosts", "chmod 0600 /root/.ssh/id_rsa", "mkdir /var/opt/puppet", "chown root /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 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) # 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)