Module: SupplyDrop::Plugin

Defined in:
lib/supply_drop/plugin.rb

Instance Method Summary collapse

Instance Method Details

#applyObject



34
35
36
# File 'lib/supply_drop/plugin.rb', line 34

def apply
  puppet(:apply)
end

#lockObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/supply_drop/plugin.rb', line 38

def lock
  if should_lock?
    run <<-CHECK_LOCK
if [ -f #{puppet_lock_file} ]; then
stat -c "#{red_text("Puppet in progress, #{puppet_lock_file} owned by %U since %x")}" #{puppet_lock_file} >&2;
exit 1;
fi
    CHECK_LOCK

    run "touch #{puppet_lock_file}"
  end
end

#noopObject



30
31
32
# File 'lib/supply_drop/plugin.rb', line 30

def noop
  puppet(:noop)
end

#prepareObject



25
26
27
28
# File 'lib/supply_drop/plugin.rb', line 25

def prepare
  run "mkdir -p #{puppet_destination}"
  run "#{sudo} chown -R $USER: #{puppet_destination}"
end

#rsyncObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/supply_drop/plugin.rb', line 4

def rsync
  SupplyDrop::Util.thread_pool_size = puppet_parallel_rsync_pool_size
  servers = SupplyDrop::Util.optionally_async(find_servers_for_task(current_task), puppet_parallel_rsync)
  overrides = {}
  overrides[:user] = fetch(:user, ENV['USER'])
  overrides[:port] = fetch(:port) if exists?(:port)
  failed_servers = servers.map do |server|
    rsync_cmd = SupplyDrop::Rsync.command(
      puppet_source,
      SupplyDrop::Rsync.remote_address(server.user || fetch(:user, ENV['USER']), server.host, puppet_destination),
      :delete => true,
      :excludes => puppet_excludes,
      :ssh => ssh_options.merge(server.options[:ssh_options]||{}).merge(overrides)
    )
    logger.debug rsync_cmd
    server.host unless system rsync_cmd
  end.compact

  raise "rsync failed on #{failed_servers.join(',')}" if failed_servers.any?
end

#unlockObject



51
52
53
# File 'lib/supply_drop/plugin.rb', line 51

def unlock
  run "#{sudo} rm -f #{puppet_lock_file}; true" if should_lock?
end