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, #pass_through_params, #playbook_dir, #project_path, #require_configuration, #template, #template!, #template_dir

Methods included from Ansible

#ansible_command

Constructor Details

#initialize(args, options) ⇒ Init

Returns a new instance of Init.



5
6
7
8
9
10
11
# File 'lib/subspace/commands/init.rb', line 5

def initialize(args, options)
  if args.first == "vars"
    init_vars
  else
    run
  end
end

Instance Method Details

#init_varsObject



63
64
65
66
# File 'lib/subspace/commands/init.rb', line 63

def init_vars
  FileUtils.mkdir_p File.join dest_dir, "templates"
  copy "templates/application.yml.template"
end

#runObject



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

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"
  end

  FileUtils.mkdir_p File.join dest_dir, "group_vars"
  FileUtils.mkdir_p File.join dest_dir, "host_vars"
  FileUtils.mkdir_p File.join dest_dir, "vars"
  FileUtils.mkdir_p File.join dest_dir, "roles"

  copy ".gitignore"
  #template "../provision.rb"
  template "ansible.cfg"
  template "hosts"
  template "group_vars/all"

  create_vault_pass
  environments.each do |env|
    @env = env
    @hostname = hostname(env)
    template "group_vars/template", "group_vars/#{env}"
    template "host_vars/template", "host_vars/#{env}"
    create_vars_file_for_env env
    template "playbook.yml", "#{env}.yml"
  end
  create_vars_file_for_env "development"
  init_vars

  puts """
  1. Create a server.

  2. Set your server's location:

    vim config/provision/host_vars/production
    vim config/provision/host_vars/dev

  3. Set up your authorized_keys:

    vim config/provision/authorized_keys

  4. Then provision your server:

    subspace provision dev
    subspace provision production

"""

end