Class: VagrantPlugins::Orchestrate::Command::Init

Inherits:
Object
  • Object
show all
Includes:
Vagrant::Util
Defined in:
lib/vagrant-orchestrate/command/init.rb

Constant Summary collapse

DEFAULT_SHELL_PATH =
"{{YOUR_SCRIPT_PATH}}"
DEFAULT_WINRM_USERNAME =
"{{YOUR_WINRM_USERNAME}}"
DEFAULT_WINRM_PASSWORD =
"{{YOUR_WINRM_PASSWORD}}"
DEFAULT_SSH_USERNAME =
"{{YOUR_SSH_USERNAME}}"
DEFAULT_SSH_PRIVATE_KEY_PATH =
"{{YOUR_SSH_PRIVATE_KEY_PATH}}"
DEFAULT_PLUGINS =
["vagrant-orchestrate", "vagrant-managed-servers"]

Instance Method Summary collapse

Instance Method Details

#executeObject

rubocop:disable MethodLength



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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/vagrant-orchestrate/command/init.rb', line 19

def execute
  options = {}

  options[:provisioners] = []
  options[:servers] = []
  options[:environments] = []
  options[:plugins] = DEFAULT_PLUGINS
  options[:puppet_librarian_puppet] = false
  options[:puppet_hiera] = true
  options[:git] = true

  opts = OptionParser.new do |o|
    o.banner = "Usage: vagrant orchestrate init [options]"
    o.separator ""
    o.separator "Options:"
    o.separator ""

    o.on("--provision-with x,y,z", Array, "Init only certain provisioners, by type.") do |list|
      options[:provisioners] = list
    end

    o.on("--shell", "Shorthand for --provision-with shell") do
      options[:provisioners] << "shell"
    end

    o.on("--shell-paths x,y,z", Array,
         "Comma-separated list of shell scripts to run on provision. Only with --shell") do |list|
      options[:shell_paths] = list
    end

    o.on("--shell-inline command", String, "Inline script to run. Only with --shell") do |c|
      options[:shell_inline] = c
    end

    o.on("--puppet", "Shorthand for '--provision-with puppet'") do
      options[:provisioners] << "puppet"
    end

    o.on("--[no-]puppet-hiera", "Include templates for hiera. Only with --puppet") do |p|
      options[:puppet_hiera] = p
    end

    o.on("--[no-]puppet-librarian-puppet",
         "Include a Puppetfile and the vagrant-librarian-puppet plugin. Only with --puppet") do |p|
      options[:puppet_librarian_puppet] = p
    end

    o.on("--ssh-username USERNAME", String, "The username for communicating over ssh") do |u|
      options[:ssh_username] = u
    end

    o.on("--ssh-password PASSWORD", String, "The password for communicating over ssh") do |p|
      options[:ssh_password] = p
    end

    o.on("--ssh-private-key-path PATH", String, "Paths to the private key for communinicating over ssh") do |k|
      options[:ssh_private_key_path] = k
    end

    o.on("--winrm", "Use the winrm communicator") do
      options[:communicator] = "winrm"
      options[:plugins] << "vagrant-winrm-s"
    end

    o.on("--winrm-username USERNAME", String, "The username for communicating with winrm") do |u|
      options[:winrm_username] = u
    end

    o.on("--winrm-password PASSWORD", String, "The password for communicating with winrm") do |p|
      options[:winrm_password] = p
    end

    o.on("--plugins x,y,z", Array, "A comma separated list of vagrant plugins to be installed") do |p|
      options[:plugins] += p
    end

    o.on("--servers x,y,z", Array, "A CSV list of FQDNs to target managed servers") do |list|
      options[:servers] = list
    end

    o.on("--environments x,y,z", Array, "A CSV list of environments. Takes precedence over --servers") do |list|
      options[:environments] = list
    end

    o.on("--[no-]git", "Include useful templates for working in a git repository. Default is true.")

    o.on("-f", "--force", "Force overwriting of files") do
      options[:force] = true
    end

    o.on("--credentials-prompt", "Prompt for credentials when performing orchestrate operations") do
      options[:creds_prompt] = true
    end

    cfpmsg = "The path to a yaml file containing :username and :password fields to use with vagrant orchestrate"
    o.on("--credentials-file-path FILEPATH", String, cfpmsg) do |file_path|
      options[:creds_file_path] = file_path
    end

    o.on("--deployment-tracker-host host", String, "Fully qualified URL of deployment-tracker instance") do |t|
      options[:tracker_host] = t
    end
  end

  argv = parse_options(opts)
  return unless argv

  options[:shell_paths] ||= options[:shell_inline] ? [] : [DEFAULT_SHELL_PATH]
  options[:winrm_username] ||= DEFAULT_WINRM_USERNAME
  options[:winrm_password] ||= DEFAULT_WINRM_PASSWORD
  options[:communicator] ||= "ssh"
  options[:ssh_username] ||= DEFAULT_SSH_USERNAME
  options[:ssh_private_key_path] ||= DEFAULT_SSH_PRIVATE_KEY_PATH unless options[:ssh_password]

  init_puppet options
  init_environments options
  init_vagrant_files options
  init_git options
  @env.ui.info(I18n.t("vagrant.commands.init.success"), prefix: false)

  # Success, exit status 0
  0
end