Class: Rundock::Operation::Deploy

Inherits:
Base show all
Defined in:
lib/rundock/plugin/operation/deploy.rb

Overview

You can use this as following scenario.yml for example.

  • node: localhost

deploy:
  - src: /tmp/deploy_from_local_file
    dst: /tmp/deploy_dest_local_file
  - src: /tmp/deploy_from_local_dir
    dst: /tmp/deploy_dest_local_dir
  • node: anyhost-01

deploy:
  - src: /tmp/deploy_from_local_file
    dst: /tmp/deploy_dest_remote_file
  - src: /tmp/deploy_from_local_dir
    dst: /tmp/deploy_dest_remote_dir
  - src: /tmp/deploy_from_local_erb_bile
    dst: /tmp/deploy_dest_remote_file
    erb: true
    trim_mode: '-'
    binding:
      hostname:
        type: command
        value: 'hostname'
      memtotal:
        type: command
        value: "cat /proc/meminfo | grep 'MemTotal' | awk '{print $2}'"

anyhost-01:

host: 192.168.1.11
ssh_opts:
  port: 22
  user: anyuser
  key:  ~/.ssh/id_rsa

Constant Summary collapse

DEFAULT_TRIM_MODE =
'-'
DEFAULT_BINDING_TYPE =
'command'

Constants inherited from Base

Base::OperationNotImplementedError

Instance Attribute Summary

Attributes inherited from Base

#attributes, #instruction

Instance Method Summary collapse

Methods inherited from Base

#initialize, #logging

Constructor Details

This class inherits a constructor from Rundock::Operation::Base

Instance Method Details

#run(backend, attributes) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/rundock/plugin/operation/deploy.rb', line 45

def run(backend, attributes)
  options = attributes[:deploy]

  options.each do |opt|
    Logger.error('src: options not found.') if !opt.key?(:src) || opt[:src].blank?
    Logger.error('dst: options not found.') if !opt.key?(:dst) || opt[:dst].blank?

    is_erb = opt.key?(:erb) && opt[:erb]

    trim_mode = if opt.key?(:trim_mode)
                  opt[:trim_mode]
                else
                  DEFAULT_TRIM_MODE
                end

    erb_options = ''
    erb_options = " erb: true trim_mode: #{trim_mode}" if is_erb

    logging("deploy localhost: #{opt[:src]} remote:#{attributes[:nodeinfo][:host]}:#{opt[:dst]}#{erb_options}", 'info')
    Logger.debug("deploy erb binding: #{opt[:binding]}") if is_erb

    val_binding = if is_erb
                    extract_map(backend, opt[:binding])
                  else
                    {}
                  end

    if is_erb
      erb_content = conv_erb(opt[:src], trim_mode, val_binding)

      tempfile = Tempfile.new('', Dir.tmpdir)
      begin
        tempfile.write(erb_content)
        tempfile.rewind
        backend.send_file(tempfile.path, opt[:dst])
      ensure
        tempfile.close
      end
    else
      backend.send_file(opt[:src], opt[:dst])
    end
  end
end