Class: Puppet::CommandPuppet::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_plugin/puppet/command.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/puppet_plugin/puppet/command.rb', line 4

def execute
  @options = {}
  @options[:verbose]     = false
  @options[:debug]       = false
  @options[:trace]       = false
  @options[:provider]    = :virtualbox
  @options[:environment] = 'obeheer1'
  @options[:transport]   = 'vagrant'

  opts = OptionParser.new do |o|
    o.banner = "Usage: vagrant puppet fqdn ipaddress [options]"
    o.separator ""
    o.separator "Options:"
    o.separator ""

    o.on("--[no-]puppet-debug",
         "Run puppet with --debug (default to false)") do |debug|
      @options[:debug] = debug
    end

    o.on("--[no-]verbose",
         "Run puppet with --verbose (default to true)") do |verbose|
      @options[:verbose] = verbose
    end

    o.on("--[no-]trace",
         "Run puppet with --trace (default to true)") do |trace|
      @options[:trace] = trace
    end

    o.on("--environment ENV", String,
         "Specify the environment. Default is: obeheer1") do |environment|
      @options[:environment] = environment
    end


    o.on("--transport TRANSPORT", String,
         "Specify the transport. Default is: vagrant") do |transport|
      @options[:transport] = transport
    end


    o.on("--provider PROVIDER", String,
         "Back the machine with a specific provider") do |provider|
      @options[:provider] = provider
    end

  end
  # Parse the options
  argv = parse_options(opts)
  if argv && argv.size == 2
    @fqdn       = argv[0]
    @ipaddress  = argv[1]
    @hostname   = @fqdn.split('.').first
  else
    @env.ui.error(I18n.t("vagrant.puppet_plugin.commands.identify.need_ip_and_name"))
    return 1
  end

  @env.ui.info(I18n.t(
    "vagrant.puppet_plugin.commands.identify.starting",
    hostname: @fqdn,
    ipaddress: @ipaddress))
  #
  # Get default machine from Vagrantfile
  #
  machine = @env.machine(:default, @options[:provider])
  #
  # Set name and ipadress based on parameters
  #
  set_machine_name(machine)
  set_name_and_ip(machine)
  set_shell_command(machine)
  set_puppet_options(machine)
  #
  # Check what state we are in and act accordingly
  #
  if machine.state.id == :running
    machine.action(:provision, @options)
  else
    machine.action(:up, @options)
  end
end