Sha256: 88ba97bac6135036b3ddc3b174d420edaf70646d80f6e7199daa5687f84ca6c2

Contents?: true

Size: 1.35 KB

Versions: 59

Compression:

Stored size: 1.35 KB

Contents

class Subspace::Commands::Vars < Subspace::Commands::Base
  def initialize(args, options)
    @environment = args.first
    @action = if options.edit
      "edit"
    elsif options.create
      "create"
    else
      "view"
    end

    run
  end

  def run
    case @action
    when "create"
      create_local
    when "view", "edit"
      ansible_command "ansible-vault", @action, "vars/#{@environment}.yml"
    else
      abort "Invalid vars command"
    end
  end

  def create_local
    if File.exists? File.join(project_path, "config/application.yml")
      answer = ask "config/application.yml already exists. Reply 'yes' to overwrite: [no] "
      abort unless answer == "yes"
    end
    src = application_yml_template
    dest = "config/application.yml"
    vars_file = File.join(project_path, "config/provision/vars/#{@environment}.yml")
    extra_vars = "project_path=#{project_path} vars_file=#{vars_file} src=#{src} dest=#{dest}"
    ansible_command "ansible-playbook", File.join(playbook_dir, "local_template.yml"), "--extra-vars", extra_vars
    say "File created at config/application.yml with #{@environment} secrets"
    say "-------------------------------------------------------------------\n"

    system "cat", "config/application.yml"
  end

  private

  def application_yml_template
    "config/provision/templates/application.yml.template"
  end

end

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
subspace-0.6.16 lib/subspace/commands/vars.rb
subspace-0.6.15 lib/subspace/commands/vars.rb
subspace-0.5.15 lib/subspace/commands/vars.rb
subspace-0.5.14 lib/subspace/commands/vars.rb
subspace-0.4.14 lib/subspace/commands/vars.rb
subspace-0.4.13 lib/subspace/commands/vars.rb
subspace-0.4.11 lib/subspace/commands/vars.rb
subspace-0.4.10 lib/subspace/commands/vars.rb
subspace-0.4.9 lib/subspace/commands/vars.rb
subspace-0.4.8 lib/subspace/commands/vars.rb
subspace-0.4.7 lib/subspace/commands/vars.rb
subspace-0.4.6 lib/subspace/commands/vars.rb
subspace-0.4.5 lib/subspace/commands/vars.rb
subspace-0.4.4 lib/subspace/commands/vars.rb
subspace-0.4.3 lib/subspace/commands/vars.rb
subspace-0.4.2 lib/subspace/commands/vars.rb
subspace-0.4.1 lib/subspace/commands/vars.rb
subspace-0.4.0 lib/subspace/commands/vars.rb
subspace-0.3.0 lib/subspace/commands/vars.rb