Class: Subspace::Commands::Init

Inherits:
Base
  • Object
show all
Defined in:
lib/subspace/commands/init.rb

Instance Method Summary collapse

Methods inherited from Base

#confirm_overwrite, #copy, #dest_dir, #gem_path, #inventory, #pass_through_params, #playbook_dir, #project_name, #project_path, #require_configuration, #set_subspace_version, #template, #template!, #template_dir

Methods included from Ansible

#ansible_command, #ansible_playbook

Constructor Details

#initialize(args, options) ⇒ Init

Returns a new instance of Init.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/subspace/commands/init.rb', line 5

def initialize(args, options)
  options.default env: "dev"

  @env = options.env
  @template = options.template

  if options.ansibe.nil? && options.terraform.nil?
    # They didn't pass in any options (subspace init) so just do both
    options.ansible = true
    options.terraform = true
  end

  if @template.nil? && options.terraform == true
    answer = ask "What template/server configuration would you like to use? e.g. 'workhorse' or 'oxenwagen'"
    @template = answer
  end

  @init_ansible = options.ansible
  @init_terraform = options.terraform
  run
end

Instance Method Details

#runObject



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
# File 'lib/subspace/commands/init.rb', line 27

def run
  if File.exists? dest_dir
    answer = ask "Subspace appears to be initialized.  Reply 'yes' to continue anyway: [no] "
    abort unless answer.chomp == "yes"
  else
    FileUtils.mkdir_p dest_dir
  end

  init_pemfile
  init_ansible if @init_ansible
  init_terraform if @init_terraform

  puts """
  1. Inspect key config files:
    - config/subspace/terraform/#{@env}/main.tf     # Main terraform file
    - config/subspace/#{@env}.yml                   # Main ansible playbook
    - config/subspace/group_vars                    # Ansible configuration options
    - config/subspace/inventory.yml                 # Server Inventory
    - config/subspace/templates/authorized_keys     # SSH Authorized Keys
    - config/subspace/templates/application.yml     # Application Environment variables

  2. create cloud infrastructure with terraform:

    subspace tf #{@env}

  3. Bootstrap the new server

    subspace boostrap #{@env}1

  4. Inspect new environment
    - ensure the correct roles are present in #{@env}.yml
    - Check ansible configuration variables in group_vars/#{@env}

  4. Provision the new servers with ansible:

    subspace provision #{@env}

  !!MAKE SURE YOU PUT config/subspace/subspace.pem SOMEWHERE!!

"""

end