summaryrefslogtreecommitdiff
path: root/lib/leap_cli/remote/puppet_plugin.rb
blob: 9c4138023b8aff5c99e95960486569106887633f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#
# these methods are made available in capistrano tasks as 'puppet.method_name'
# (see RemoteCommand::new_capistrano)
#

module LeapCli; module Remote; module PuppetPlugin

  def apply(options)
    run "#{PUPPET_DESTINATION}/bin/puppet_command set_hostname apply #{flagize(options)}"
  end

  private

  def flagize(hsh)
    hsh.inject([]) {|str, item|
      if item[1] === false
        str
      elsif item[1] === true
        str << "--" + item[0].to_s
      else
        str << "--" + item[0].to_s + " " + item[1].to_s
      end
    }.join(' ')
  end

end; end; end


    # def puppet(command = :noop)
    #   #puppet_cmd = "cd #{puppet_destination} && #{sudo_cmd} #{puppet_command} --modulepath=#{puppet_lib} #{puppet_parameters}"
    #   puppet_cmd = "cd #{puppet_destination} && #{sudo_cmd} #{puppet_command} #{puppet_parameters}"
    #   flag = command == :noop ? '--noop' : ''

    #   writer = if puppet_stream_output
    #              SupplyDrop::Writer::Streaming.new(logger)
    #            else
    #              SupplyDrop::Writer::Batched.new(logger)
    #            end

    #   writer = SupplyDrop::Writer::File.new(writer, puppet_write_to_file) unless puppet_write_to_file.nil?

    #   begin
    #     exitcode = nil
    #     run "#{puppet_cmd} #{flag}; echo exitcode:$?" do |channel, stream, data|
    #       if data =~ /exitcode:(\d+)/
    #         exitcode = $1
    #         writer.collect_output(channel[:host], "Puppet #{command} complete (#{exitcode_description(exitcode)}).\n")
    #       else
    #         writer.collect_output(channel[:host], data)
    #       end
    #     end
    #   ensure
    #     writer.all_output_collected
    #   end
    # end

    # def exitcode_description(code)
    #   case code
    #     when "0" then "no changes"
    #     when "2" then "changes made"
    #     when "4" then "failed"
    #     when "6" then "changes and failures"
    #     else code
    #   end
    # end