# canzea --role=operatingsystem --solution=centos --remote --hostname=192.34.56.119 --privateKey=/var/go/.ssh/id_rsa_digitalocean require 'net/ssh' require 'net/sftp' require 'json' class RemoteCall def init (hostname, privateKey) cmd1 = "yum -y install git" cmd2 = "(rm -rf ike-environments && git clone https://IKE_CI:55665566@gitlab.com/ikethecoder/ike-environments.git)" cmd3 = 'find /root/ike-environments -name "*.sh" -exec chmod +x {} +' cmd4 = '(cd /root/ike-environments/environment/production && ./roles/workarounds/ruby/install.sh)' cmd5 = '(cd /root/ike-environments/environment/production && ./roles/workarounds/ruby-gems/install.sh)' cmd6 = '(cd /root/ike-environments/environment/production && ./roles/workarounds/sshd/configure.sh)' cmd7 = '(cd /root/ike-environments/environment/production && ./roles/workarounds/sshd/enable.sh)' cmd8 = '(cd /root/ike-environments/environment/production && ./roles/workarounds/canzea/install-root.sh)' exec hostname, privateKey, cmd1 exec hostname, privateKey, cmd2 exec hostname, privateKey, cmd3 exec hostname, privateKey, cmd4 exec hostname, privateKey, cmd5 exec hostname, privateKey, cmd6 exec hostname, privateKey, cmd7 exec hostname, privateKey, cmd8 end def run (hostname, privateKey, cmd) @cmd = ". .bash_profile && cd .local/bin/ike-environments/environment/production && #{cmd}" exec hostname, privateKey, @cmd end def exec (hostname, privateKey, cmd) @username = "root" Net::SSH.start(hostname, @username, :paranoid => false, :keys => [privateKey]) do |ssh| chan = ssh.open_channel do |channel| channel[:data] = "" channel.request_pty channel.env("DIGITAL_OCEAN_API_KEY", ENV['DIGITAL_OCEAN_API_KEY']) channel.env("VAULT_TOKEN", ENV['VAULT_TOKEN']) channel.env("CONSUL_URL", ENV['CONSUL_URL']) channel.env("WORK_DIR", ENV['WORK_DIR']) channel.exec(cmd) do |ch, success| abort "could not execute command" unless success channel.on_data do |ch, data| channel[:data] << data end channel.on_request("exit-status") do |ch, data| exit_code = data.read_long if (exit_code == 0) else abort(channel[:data]) end end channel.on_close do |ch| puts channel[:data] end end end chan.wait end end end