subspace 0.1.1 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/.ruby-version +1 -1
- data/.travis.yml +1 -1
- data/CHANGELOG.md +380 -0
- data/README.md +511 -9
- data/TODO +34 -0
- data/UPGRADING.md +10 -0
- data/ansible/playbooks/local_template.yml +13 -0
- data/ansible/playbooks/maintenance_mode.yml +5 -0
- data/ansible/roles/alienvault/tasks/main.yml +29 -0
- data/ansible/roles/apache/defaults/main.yml +2 -5
- data/ansible/roles/apache/handlers/main.yml +9 -1
- data/ansible/roles/apache/tasks/main.yml +37 -9
- data/ansible/roles/apache/templates/server_status.conf +6 -0
- data/ansible/roles/apache-rails/tasks/main.yml +26 -0
- data/ansible/roles/apache-rails/templates/_canonical_domain.conf +10 -0
- data/ansible/roles/apache-rails/templates/_rails.conf +23 -0
- data/ansible/roles/apache-rails/templates/project-ssl.conf +23 -0
- data/ansible/roles/apache-rails/templates/project.conf +5 -0
- data/ansible/roles/collectd/defaults/main.yml +3 -0
- data/ansible/roles/collectd/handlers/main.yml +3 -0
- data/ansible/roles/collectd/tasks/main.yml +82 -0
- data/ansible/roles/collectd/templates/apache2.conf +6 -0
- data/ansible/roles/collectd/templates/delayed_job_postgres.conf +21 -0
- data/ansible/roles/collectd/templates/df.conf +16 -0
- data/ansible/roles/collectd/templates/graphite.conf +14 -0
- data/ansible/roles/collectd/templates/hostname.conf +2 -0
- data/ansible/roles/collectd/templates/nginx.conf +28 -0
- data/ansible/roles/collectd/templates/nodejs-process.conf +3 -0
- data/ansible/roles/collectd/templates/puma-process.conf +3 -0
- data/ansible/roles/collectd/templates/rails_lograge.conf +31 -0
- data/ansible/roles/common/defaults/main.yml +2 -1
- data/ansible/roles/common/files/sudoers-service +1 -0
- data/ansible/roles/common/tasks/main.yml +307 -19
- data/ansible/roles/common/tasks/no_swap.yml +26 -0
- data/ansible/roles/common/tasks/swap.yml +34 -8
- data/ansible/roles/common/templates/motd +13 -0
- data/ansible/roles/common/templates/motd2 +24 -0
- data/ansible/roles/common/templates/terminalcolor +25 -0
- data/ansible/roles/delayed_job/README.md +2 -4
- data/ansible/roles/delayed_job/defaults/main.yml +0 -2
- data/ansible/roles/delayed_job/handlers/main.yml +1 -1
- data/ansible/roles/delayed_job/tasks/main.yml +22 -29
- data/ansible/roles/delayed_job/templates/delayed-job-monit-rc +6 -5
- data/ansible/roles/delayed_job/templates/delayed-job-systemd.service +33 -0
- data/ansible/roles/gem-patch-report/README.md +137 -0
- data/ansible/roles/gem-patch-report/defaults/main.yml +2 -0
- data/ansible/roles/gem-patch-report/tasks/main.yml +89 -0
- data/ansible/roles/gem-patch-report/templates/gem-patch-report.sh.j2 +114 -0
- data/ansible/roles/letsencrypt/defaults/main.yml +11 -1
- data/ansible/roles/letsencrypt/tasks/legacy.yml +44 -0
- data/ansible/roles/letsencrypt/tasks/main.yml +72 -76
- data/ansible/roles/letsencrypt/tasks/modern.yml +39 -0
- data/ansible/roles/logrotate/LICENSE +27 -0
- data/ansible/roles/logrotate/README.md +70 -0
- data/ansible/roles/logrotate/defaults/main.yml +2 -0
- data/ansible/roles/logrotate/meta/main.yml +18 -0
- data/ansible/roles/logrotate/tasks/main.yml +15 -0
- data/ansible/roles/logrotate/templates/logrotate.d.j2 +16 -0
- data/ansible/roles/memcache/defaults/main.yml +2 -0
- data/ansible/roles/memcache/tasks/main.yml +16 -1
- data/ansible/roles/mysql/meta/main.yml +1 -1
- data/ansible/roles/mysql/tasks/main.yml +2 -2
- data/ansible/roles/mysql2_gem/meta/main.yml +1 -1
- data/ansible/roles/mysql2_gem/tasks/main.yml +1 -1
- data/ansible/roles/newrelic/tasks/main.yml +8 -1
- data/ansible/roles/newrelic-infra/defaults/main.yml +2 -0
- data/ansible/roles/newrelic-infra/handlers/main.yml +5 -0
- data/ansible/roles/newrelic-infra/tasks/main.yml +38 -0
- data/ansible/roles/newrelic-infra/templates/logs.yml.j2 +5 -0
- data/ansible/roles/newrelic-infra/templates/newrelic-infra.yml.j2 +2 -0
- data/ansible/roles/nginx/defaults/main.yml +4 -0
- data/ansible/roles/nginx/handlers/main.yml +12 -0
- data/ansible/roles/nginx/tasks/main.yml +113 -14
- data/ansible/roles/nginx/templates/nginx.conf +29 -0
- data/ansible/roles/nginx/templates/status +10 -0
- data/ansible/roles/nginx-maintenance/tasks/main.yml +33 -0
- data/ansible/roles/nginx-rails/defaults/main.yml +6 -0
- data/ansible/roles/nginx-rails/tasks/main.yml +54 -0
- data/ansible/roles/nginx-rails/templates/_asset_cors.conf +11 -0
- data/ansible/roles/nginx-rails/templates/_rails.conf +35 -0
- data/ansible/roles/nginx-rails/templates/_upstream.conf +11 -0
- data/ansible/roles/nginx-rails/templates/default_server +5 -0
- data/ansible/roles/nginx-rails/templates/nginx-project +9 -0
- data/ansible/roles/nginx-rails/templates/nginx-project-ssl +23 -0
- data/ansible/roles/nodejs/tasks/main.yml +33 -0
- data/ansible/roles/papertrail/tasks/main.yml +23 -4
- data/ansible/roles/papertrail/templates/log_files.yml +8 -1
- data/ansible/roles/postgis/.gitignore +3 -0
- data/ansible/roles/postgis/CHANGELOG.md +24 -0
- data/ansible/roles/postgis/LICENSE +202 -0
- data/ansible/roles/postgis/README.md +12 -0
- data/ansible/roles/postgis/meta/main.yml +15 -0
- data/ansible/roles/postgis/tasks/main.yml +20 -0
- data/ansible/roles/postgresql/README.md +15 -0
- data/ansible/roles/postgresql/defaults/main.yml +3 -0
- data/ansible/roles/postgresql/handlers/main.yml +1 -1
- data/ansible/roles/postgresql/meta/main.yml +1 -6
- data/ansible/roles/postgresql/tasks/backups.yml +8 -6
- data/ansible/roles/postgresql/tasks/main.yml +89 -9
- data/ansible/roles/postgresql/templates/backup.sh +17 -2
- data/ansible/roles/postgresql-client/tasks/main.yml +91 -0
- data/ansible/roles/puma/tasks/main.yml +38 -19
- data/ansible/roles/puma/templates/puma-monit-rc +5 -0
- data/ansible/roles/puma/templates/puma-systemd.service +43 -0
- data/ansible/roles/puma/templates/puma-systemd.socket +14 -0
- data/ansible/roles/puma/templates/puma.rb +24 -12
- data/ansible/roles/rails/defaults/main.yml +1 -3
- data/ansible/roles/rails/tasks/main.yml +76 -18
- data/ansible/roles/rails/templates/application.yml +1 -1
- data/ansible/roles/rails/templates/database.yml +3 -3
- data/ansible/roles/redis/defaults/main.yml +2 -0
- data/ansible/roles/redis/tasks/main.yml +45 -3
- data/ansible/roles/resque/tasks/main.yml +14 -0
- data/ansible/roles/resque/templates/resque-monit-rc +4 -0
- data/ansible/roles/resque/templates/resque-systemd.service +54 -0
- data/ansible/roles/ruby-common/README.md +1 -1
- data/ansible/roles/ruby-common/defaults/main.yml +1 -0
- data/ansible/roles/ruby-common/tasks/main.yml +55 -13
- data/ansible/roles/sidekiq/README.md +1 -0
- data/ansible/roles/sidekiq/defaults/main.yml +2 -0
- data/ansible/roles/sidekiq/tasks/main.yml +15 -0
- data/ansible/roles/sidekiq/templates/sidekiq-monit-rc +4 -0
- data/ansible/roles/sidekiq/templates/sidekiq-systemd.service +63 -0
- data/ansible/roles/tailscale/defaults/main.yml +2 -0
- data/ansible/roles/tailscale/tasks/main.yml +40 -0
- data/ansible/roles/yarn/tasks/main.yml +19 -0
- data/ansible/roles/zenoamaro.postgresql/.gitignore +1 -0
- data/ansible/roles/zenoamaro.postgresql/.travis.yml +28 -0
- data/ansible/roles/zenoamaro.postgresql/LICENSE.md +21 -0
- data/ansible/roles/zenoamaro.postgresql/README.md +117 -0
- data/ansible/roles/zenoamaro.postgresql/Vagrantfile +62 -0
- data/ansible/roles/zenoamaro.postgresql/boxed.yml +26 -0
- data/ansible/roles/zenoamaro.postgresql/defaults/main.yml +607 -0
- data/ansible/roles/zenoamaro.postgresql/handlers/main.yml +8 -0
- data/ansible/roles/zenoamaro.postgresql/inventory +19 -0
- data/ansible/roles/zenoamaro.postgresql/main.yml +19 -0
- data/ansible/roles/zenoamaro.postgresql/meta/.galaxy_install_info +1 -0
- data/ansible/roles/zenoamaro.postgresql/meta/main.yml +21 -0
- data/ansible/roles/zenoamaro.postgresql/tasks/configure.yml +55 -0
- data/ansible/roles/zenoamaro.postgresql/tasks/extensions.yml +49 -0
- data/ansible/roles/zenoamaro.postgresql/tasks/install.yml +51 -0
- data/ansible/roles/zenoamaro.postgresql/tasks/main.yml +5 -0
- data/ansible/roles/zenoamaro.postgresql/templates/environment +11 -0
- data/ansible/roles/zenoamaro.postgresql/templates/pg_ctl.conf +5 -0
- data/ansible/roles/zenoamaro.postgresql/templates/pg_hba.conf +112 -0
- data/ansible/roles/zenoamaro.postgresql/templates/pg_ident.conf +46 -0
- data/ansible/roles/zenoamaro.postgresql/templates/postgresql.conf +536 -0
- data/ansible/roles/zenoamaro.postgresql/test.yml +24 -0
- data/bin/console +0 -4
- data/exe/subspace +3 -84
- data/lib/subspace/cli.rb +168 -0
- data/lib/subspace/commands/ansible.rb +35 -0
- data/lib/subspace/commands/base.rb +94 -0
- data/lib/subspace/commands/bootstrap.rb +49 -0
- data/lib/subspace/commands/configure.rb +27 -0
- data/lib/subspace/commands/exec.rb +20 -0
- data/lib/subspace/commands/init.rb +144 -0
- data/lib/subspace/commands/inventory.rb +54 -0
- data/lib/subspace/commands/maintain.rb +16 -0
- data/lib/subspace/commands/maintenance_mode.rb +16 -0
- data/lib/subspace/commands/override.rb +21 -0
- data/lib/subspace/commands/provision.rb +14 -0
- data/lib/subspace/commands/secrets.rb +69 -0
- data/lib/subspace/commands/ssh.rb +33 -0
- data/lib/subspace/commands/terraform.rb +89 -0
- data/lib/subspace/configuration.rb +71 -0
- data/lib/subspace/inventory.rb +144 -0
- data/lib/subspace/version.rb +1 -1
- data/lib/subspace.rb +8 -1
- data/subspace.gemspec +14 -3
- data/template/provision.rb.erb +94 -0
- data/template/subspace/.gitignore +6 -0
- data/template/subspace/ansible.cfg.erb +17 -0
- data/template/subspace/group_vars/all.erb +28 -0
- data/template/subspace/group_vars/template.erb +26 -0
- data/template/subspace/inventory.yml.erb +12 -0
- data/template/subspace/playbook.yml.erb +18 -0
- data/template/subspace/secrets/template.erb +5 -0
- data/template/subspace/templates/application.yml.template +27 -0
- data/template/subspace/templates/authorized_keys.erb +1 -0
- data/template/subspace/terraform/.gitignore +2 -0
- data/template/subspace/terraform/template/main-oxenwagen.tf.erb +116 -0
- data/template/subspace/terraform/template/main-workhorse.tf.erb +41 -0
- data/template/subspace/terraformrc.erb +9 -0
- data/terraform/modules/s3_backend/README +2 -0
- data/terraform/modules/s3_backend/dynamodb.tf +1 -0
- data/terraform/modules/s3_backend/iam_user.tf +38 -0
- data/terraform/modules/s3_backend/main.tf +39 -0
- data/terraform/modules/s3_backend/state_bucket.tf +14 -0
- metadata +198 -29
- data/ansible/roles/apache/templates/project.conf +0 -25
- data/ansible/roles/aws/tasks/main.yml +0 -46
- data/ansible/roles/delayed_job/files/deploy-service +0 -2
- data/ansible/roles/delayed_job/files/monit-http.conf +0 -3
- data/ansible/roles/letsencrypt/templates/project-le-ssl.conf +0 -31
- data/ansible/roles/nginx/templates/nginx-project +0 -27
- data/ansible/roles/puma/templates/etc-init-puma-manager.conf +0 -31
- data/ansible/roles/puma/templates/etc-init-puma.conf +0 -69
- data/lib/subspace/railtie.rb +0 -9
- data/lib/tasks/provision.rake +0 -12
- data/template/provision/.gitignore +0 -1
- data/template/provision/ansible.cfg.erb +0 -5
- data/template/provision/group_vars/all.erb +0 -12
- data/template/provision/group_vars/template.erb +0 -14
- data/template/provision/host_vars/template.erb +0 -4
- data/template/provision/playbook.yml.erb +0 -26
- data/template/provision/vars/template.erb +0 -4
- /data/template/{provision → subspace}/hosts.erb +0 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
class Subspace::Commands::Secrets < Subspace::Commands::Base
|
|
2
|
+
def initialize(args, options)
|
|
3
|
+
if args.first == "rekey"
|
|
4
|
+
rekey
|
|
5
|
+
else
|
|
6
|
+
@environment = args.first
|
|
7
|
+
@action = if options.edit
|
|
8
|
+
"edit"
|
|
9
|
+
elsif options.create
|
|
10
|
+
"create"
|
|
11
|
+
else
|
|
12
|
+
"view"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
run
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def run
|
|
20
|
+
update_ansible_cfg
|
|
21
|
+
case @action
|
|
22
|
+
when "create"
|
|
23
|
+
create_local
|
|
24
|
+
when "view", "edit"
|
|
25
|
+
ansible_command "ansible-vault", @action, "secrets/#{@environment}.yml"
|
|
26
|
+
else
|
|
27
|
+
abort "Invalid secrets command"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def create_local
|
|
32
|
+
if File.exist? File.join(project_path, "config/application.yml")
|
|
33
|
+
answer = ask "config/application.yml already exists. Reply 'yes' to overwrite: [no] "
|
|
34
|
+
abort unless answer == "yes"
|
|
35
|
+
end
|
|
36
|
+
src = application_yml_template
|
|
37
|
+
dest = "config/application.yml"
|
|
38
|
+
vars_file = File.join(project_path, dest_dir, "/secrets/#{@environment}.yml")
|
|
39
|
+
extra_vars = "project_path=#{project_path} vars_file=#{vars_file} src=#{src} dest=#{dest}"
|
|
40
|
+
ansible_command "ansible-playbook", File.join(playbook_dir, "local_template.yml"), "--extra-vars", extra_vars
|
|
41
|
+
say "File created at config/application.yml with #{@environment} secrets"
|
|
42
|
+
say "-------------------------------------------------------------------\n"
|
|
43
|
+
|
|
44
|
+
system "cat", "config/application.yml"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def rekey
|
|
48
|
+
secret_files = Dir.glob("config/subspace/secrets/*.yml").map {|x| "secrets/#{File.basename(x)}"}
|
|
49
|
+
exit unless agree("This will re-key your secrets with a new random vault_pass. (#{secret_files}). Proceed? (yes to continue) ")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
say "Writing new password to .vault_pass.new"
|
|
53
|
+
File.write "config/subspace/.vault_pass.new", SecureRandom.base64(24) + "\n"
|
|
54
|
+
success = ansible_command "ansible-vault", "rekey", "--vault-password-file", ".vault_pass", "--new-vault-password-file", ".vault_pass.new", "-v", *secret_files
|
|
55
|
+
if success
|
|
56
|
+
FileUtils.mv "config/subspace/.vault_pass", "config/subspace/.vault_pass.old"
|
|
57
|
+
FileUtils.mv "config/subspace/.vault_pass.new", "config/subspace/.vault_pass"
|
|
58
|
+
else
|
|
59
|
+
say "Something went wrong, not changing .vault_pass"
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
def application_yml_template
|
|
66
|
+
"#{dest_dir}/templates/application.yml.template"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'yaml'
|
|
2
|
+
require 'subspace/inventory'
|
|
3
|
+
class Subspace::Commands::Ssh < Subspace::Commands::Base
|
|
4
|
+
PASS_THROUGH_PARAMS = ["i"]
|
|
5
|
+
|
|
6
|
+
def initialize(args, options)
|
|
7
|
+
@host = args.first
|
|
8
|
+
@user = options.user
|
|
9
|
+
@options = options
|
|
10
|
+
run
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def run
|
|
14
|
+
if !inventory.hosts[@host]
|
|
15
|
+
say "No host '#{@host}' found. "
|
|
16
|
+
all_hosts = inventory.hosts.keys
|
|
17
|
+
say (["Available hosts:"] + all_hosts).join("\n\t")
|
|
18
|
+
return
|
|
19
|
+
end
|
|
20
|
+
host_vars = inventory.hosts[@host].vars
|
|
21
|
+
if host_vars.key?('ansible_ssh_user')
|
|
22
|
+
say "Supposed to be ansible_user not ansible_ssh_user"
|
|
23
|
+
end
|
|
24
|
+
user = @user || host_vars["ansible_user"]
|
|
25
|
+
host = host_vars["ansible_host"]
|
|
26
|
+
port = host_vars["ansible_port"] || 22
|
|
27
|
+
pem = host_vars["ansible_ssh_private_key_file"]
|
|
28
|
+
pem_cmd = "-i config/subspace/#{pem}" if pem
|
|
29
|
+
cmd = "ssh #{user}@#{host} -p #{port} #{pem_cmd} #{pass_through_params.join(" ")}"
|
|
30
|
+
say "> #{cmd} \n"
|
|
31
|
+
exec cmd
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
module Subspace
|
|
3
|
+
module Commands
|
|
4
|
+
class Terraform < Subspace::Commands::Base
|
|
5
|
+
def self.ensure_terraform
|
|
6
|
+
if `terraform -v --json | jq -r .terraform_version` =~ /1\.\d+/
|
|
7
|
+
puts "Terraform found."
|
|
8
|
+
return true
|
|
9
|
+
else
|
|
10
|
+
puts "Please install terraform at least 1.1 locally"
|
|
11
|
+
return false
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def initialize(args, options)
|
|
16
|
+
@env = args.shift
|
|
17
|
+
@args = args
|
|
18
|
+
@options = options
|
|
19
|
+
run
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def run
|
|
23
|
+
self.class.ensure_terraform or exit
|
|
24
|
+
check_aws_credentials or exit
|
|
25
|
+
if @args.any?
|
|
26
|
+
terraform_command(@args.shift, *@args)
|
|
27
|
+
else
|
|
28
|
+
puts "No command specified, running plan/apply"
|
|
29
|
+
terraform_command("init", "-upgrade") or return
|
|
30
|
+
terraform_command("apply") or return
|
|
31
|
+
update_inventory
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
def terraform_command(command, *args)
|
|
37
|
+
result = nil
|
|
38
|
+
# update_terraformrc
|
|
39
|
+
Dir.chdir "config/subspace/terraform/#{@env}" do
|
|
40
|
+
say ">> Running terraform #{command} #{args.join(' ')}"
|
|
41
|
+
result = system("terraform", command, *args, out: $stdout, err: $stderr)
|
|
42
|
+
say "<< Done"
|
|
43
|
+
end
|
|
44
|
+
result
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def update_terraformrc
|
|
48
|
+
template! "terraformrc", ".terraformrc"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def update_inventory
|
|
52
|
+
puts "Apply succeeded, updating inventory."
|
|
53
|
+
Dir.chdir "config/subspace/terraform/#{@env}" do
|
|
54
|
+
@output = JSON.parse `terraform output -json inventory`
|
|
55
|
+
end
|
|
56
|
+
inventory.merge(@output)
|
|
57
|
+
inventory.write
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def check_aws_credentials
|
|
61
|
+
Dir.chdir "config/subspace/terraform/#{@env}" do
|
|
62
|
+
if File.read("./main.tf") =~ /^\s+cloud {$/
|
|
63
|
+
puts "Detected terraform cloud, skipping credential check"
|
|
64
|
+
return true
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
ENV["AWS_ACCESS_KEY_ID"] = nil
|
|
69
|
+
ENV["AWS_SECRET_ACCESS_KEY"] = nil
|
|
70
|
+
|
|
71
|
+
profile = "subspace-#{project_name}"
|
|
72
|
+
|
|
73
|
+
system("aws --profile #{profile} configure list &> /dev/null ")
|
|
74
|
+
if $? != 0
|
|
75
|
+
puts "No AWS Profile '#{profile}' configured. Please enter your credentials."
|
|
76
|
+
system("aws --profile #{profile} configure")
|
|
77
|
+
system("aws --profile #{profile} configure list &> /dev/null ")
|
|
78
|
+
if $? != 0
|
|
79
|
+
puts "FATAL: could not configure aws. Please try again"
|
|
80
|
+
exit
|
|
81
|
+
end
|
|
82
|
+
else
|
|
83
|
+
puts "Using AWS Profile #{profile}"
|
|
84
|
+
end
|
|
85
|
+
true
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
require "ostruct"
|
|
2
|
+
class Subspace::Configuration
|
|
3
|
+
attr_accessor :project_name
|
|
4
|
+
attr_reader :vars, :host_config, :group_config
|
|
5
|
+
|
|
6
|
+
def initialize
|
|
7
|
+
@host_config = {}
|
|
8
|
+
@group_config = {}
|
|
9
|
+
@vars = OpenStruct.new
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def host(name, options)
|
|
13
|
+
@host_config[name] = options
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def hosts
|
|
17
|
+
@host_config.keys
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def groups
|
|
21
|
+
@group_config.keys
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def group(name, hosts: [], vars: {})
|
|
25
|
+
group_config(name).hosts += hosts
|
|
26
|
+
group_config(name).vars.merge!(vars)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def role(name, groups: [], vars: {})
|
|
30
|
+
groups.each do |group|
|
|
31
|
+
group_config(group).roles.push(name.to_sym)
|
|
32
|
+
vars.each do |k,v|
|
|
33
|
+
if group_config(group).vars[k]
|
|
34
|
+
put "Warning, variable '#{k}' already set for group '#{group}'"
|
|
35
|
+
end
|
|
36
|
+
group_config(group).vars[k] = v
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# I think a better way to do this is possibly to just write out all the host vars directly to a yaml file
|
|
42
|
+
# That provides more flexibility, although this method provides a whitelist.
|
|
43
|
+
def binding_for(host: nil, group: nil)
|
|
44
|
+
config = @vars.dup
|
|
45
|
+
if host
|
|
46
|
+
@host_config[host].each do |k,v|
|
|
47
|
+
config[k] = v
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
b = binding
|
|
51
|
+
b.local_variable_set(:config, config)
|
|
52
|
+
b
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
private
|
|
56
|
+
|
|
57
|
+
def group_config(group)
|
|
58
|
+
@group_config[group.to_sym] ||= GroupConfig.new(group)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
class GroupConfig
|
|
62
|
+
attr_reader :name, :vars
|
|
63
|
+
attr_accessor :hosts, :roles
|
|
64
|
+
def initialize(name)
|
|
65
|
+
@name = name.to_sym
|
|
66
|
+
@hosts = []
|
|
67
|
+
@roles = []
|
|
68
|
+
@vars = OpenStruct.new
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
require 'yaml'
|
|
2
|
+
module Subspace
|
|
3
|
+
class Inventory
|
|
4
|
+
attr_accessor :group_vars, :hosts, :global_vars, :path
|
|
5
|
+
def initialize
|
|
6
|
+
@hosts = {}
|
|
7
|
+
@group_vars = {}
|
|
8
|
+
@global_vars = {}
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Find all the hosts in the host/group or exit
|
|
12
|
+
def find_hosts!(host_spec)
|
|
13
|
+
if self.groups[host_spec]
|
|
14
|
+
return self.groups[host_spec].host_list.map { |m| self.hosts[m] }
|
|
15
|
+
elsif self.hosts[host_spec]
|
|
16
|
+
return [self.hosts[host_spec]]
|
|
17
|
+
else
|
|
18
|
+
say "No inventory matching: '#{host_spec}' found. "
|
|
19
|
+
say (["Available hosts:"] + self.hosts.keys).join("\n\t")
|
|
20
|
+
say (["Available groups:"] + self.groups.keys).join("\n\t")
|
|
21
|
+
exit
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.read(path)
|
|
26
|
+
inventory = new
|
|
27
|
+
inventory.path = path
|
|
28
|
+
|
|
29
|
+
yml = YAML.load(File.read(path)).to_h
|
|
30
|
+
|
|
31
|
+
# Run through all hosts
|
|
32
|
+
yml["all"]["hosts"].each do |name, vars|
|
|
33
|
+
inventory.hosts[name] = Host.new(name, vars: vars || {})
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Run through all children (groups)
|
|
37
|
+
# This does NOT handle sub-groups yet
|
|
38
|
+
yml["all"]["children"].each do |name, group|
|
|
39
|
+
next unless group["hosts"]
|
|
40
|
+
|
|
41
|
+
# Each group defines its host membership
|
|
42
|
+
group["hosts"].each do |host, vars|
|
|
43
|
+
inventory.hosts[host] ||= Host.new(host, vars: vars || {})
|
|
44
|
+
inventory.hosts[host].group_list.push name
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
if group["vars"]
|
|
48
|
+
inventory.group_vars[name] = group["vars"]
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Capture global variables
|
|
53
|
+
inventory.global_vars = yml["all"]["vars"] || {}
|
|
54
|
+
|
|
55
|
+
inventory
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def write(path=nil)
|
|
59
|
+
File.write(@path || path, self.to_yml)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def merge(inventory_json)
|
|
63
|
+
inventory_json["hostnames"].each_with_index do |host, i|
|
|
64
|
+
if hosts[host]
|
|
65
|
+
old_ip = hosts[host].vars["ansible_host"]
|
|
66
|
+
new_ip = inventory_json["ip_addresses"][i]
|
|
67
|
+
if old_ip != new_ip
|
|
68
|
+
say " * Host '#{host}' IP address changed! You may need to update the inventory! (#{old_ip} => #{new_ip})"
|
|
69
|
+
end
|
|
70
|
+
next
|
|
71
|
+
end
|
|
72
|
+
hosts[host] = Host.new(host)
|
|
73
|
+
hosts[host].vars["ansible_host"] = inventory_json["ip_addresses"][i]
|
|
74
|
+
hosts[host].vars["ansible_user"] = inventory_json["users"][i]
|
|
75
|
+
hosts[host].vars["hostname"] = host
|
|
76
|
+
hosts[host].group_list = inventory_json["groups"][i].split(/\s/)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def to_yml
|
|
81
|
+
all_groups = {}
|
|
82
|
+
all_hosts = {}
|
|
83
|
+
@hosts.each do |name, host|
|
|
84
|
+
all_hosts[host.name] = host.vars.empty? ? nil : host.vars.transform_keys(&:to_s)
|
|
85
|
+
host.group_list.each do |group|
|
|
86
|
+
all_groups[group] ||= { "hosts" => {}}
|
|
87
|
+
all_groups[group]["hosts"][host.name] = nil
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
@group_vars.each do |group, vars|
|
|
92
|
+
all_groups[group] ||= {}
|
|
93
|
+
if !vars.empty?
|
|
94
|
+
all_groups[group]["vars"] = vars.transform_keys(&:to_s)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
yml = {
|
|
99
|
+
"all" => {
|
|
100
|
+
"hosts" => all_hosts,
|
|
101
|
+
"children" => all_groups.empty? ? nil : all_groups
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if !@global_vars.empty?
|
|
106
|
+
yml["all"]["vars"] = @global_vars.transform_keys(&:to_s)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
YAML.dump(yml)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def groups
|
|
113
|
+
@groups ||= begin
|
|
114
|
+
all_groups = {"all" => Group.new("all", vars: {}, host_list: hosts.keys) }
|
|
115
|
+
@hosts.each do |name, host|
|
|
116
|
+
host.group_list.each do |group|
|
|
117
|
+
all_groups[group] ||= Group.new(group, vars: @group_vars[group])
|
|
118
|
+
all_groups[group].host_list.append(name)
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
all_groups
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
class Host
|
|
126
|
+
attr_accessor :vars, :group_list, :name
|
|
127
|
+
|
|
128
|
+
def initialize(name, vars: {}, group_list: [])
|
|
129
|
+
@name = name
|
|
130
|
+
@vars = vars
|
|
131
|
+
@group_list = group_list
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
class Group
|
|
136
|
+
attr_accessor :name, :vars, :host_list
|
|
137
|
+
def initialize(name, vars: {}, host_list: [])
|
|
138
|
+
@name = name
|
|
139
|
+
@vars = vars
|
|
140
|
+
@host_list = host_list
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
data/lib/subspace/version.rb
CHANGED
data/lib/subspace.rb
CHANGED
data/subspace.gemspec
CHANGED
|
@@ -13,6 +13,13 @@ Gem::Specification.new do |spec|
|
|
|
13
13
|
spec.description = %q{WIP -- don't use this :)}
|
|
14
14
|
spec.homepage = "https://github.com/tenforwardconsulting/subspace"
|
|
15
15
|
spec.license = "MIT"
|
|
16
|
+
spec.post_install_message = <<~EOS
|
|
17
|
+
*** Subspace 3 has many breaking changes
|
|
18
|
+
Primarily, the entire configuration directory structure has moved from config/provision to config/subspace.
|
|
19
|
+
You will need to migrate your old configuration to the new location, or downgrade to Subspace 2 if this was not intentional.
|
|
20
|
+
Please review the Upgrade guide: https://github.com/tenforwardconsulting/subspace/UPGRADING.md
|
|
21
|
+
EOS
|
|
22
|
+
|
|
16
23
|
|
|
17
24
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
18
25
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
@@ -24,10 +31,14 @@ Gem::Specification.new do |spec|
|
|
|
24
31
|
|
|
25
32
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
26
33
|
spec.bindir = "exe"
|
|
27
|
-
spec.executables
|
|
34
|
+
spec.executables << "subspace"
|
|
28
35
|
spec.require_paths = ["lib"]
|
|
29
36
|
|
|
30
|
-
spec.add_development_dependency "bundler", "~> 1
|
|
31
|
-
spec.add_development_dependency "rake", "~>
|
|
37
|
+
spec.add_development_dependency "bundler", "~> 2.1"
|
|
38
|
+
spec.add_development_dependency "rake", "~> 12.3.3"
|
|
32
39
|
spec.add_development_dependency "rspec", "~> 3.0"
|
|
40
|
+
|
|
41
|
+
spec.add_runtime_dependency "commander", "~>4.2"
|
|
42
|
+
spec.add_runtime_dependency "abbrev", "~>0.1.2"
|
|
43
|
+
spec.add_runtime_dependency "figaro", "~>1.0"
|
|
33
44
|
end
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
## Subspace configuration file
|
|
2
|
+
#
|
|
3
|
+
# This file contains all (most?) the configuration for provisioning servers to run this rails application.
|
|
4
|
+
# It uses a simple DSL that should be easy to pick up if you're comfortable with things
|
|
5
|
+
# like rails environments, devise config, capistrano, etc.
|
|
6
|
+
#
|
|
7
|
+
# When you run `subspace`, the following files be overwritten. DO NOT MANUALLY MODIFY THESE FILES.
|
|
8
|
+
#
|
|
9
|
+
# config
|
|
10
|
+
# - provision
|
|
11
|
+
# - group_vars/*
|
|
12
|
+
# - host_vars/*
|
|
13
|
+
# - ansible.cfg
|
|
14
|
+
# - hosts
|
|
15
|
+
# - playbook.yml
|
|
16
|
+
|
|
17
|
+
# Step one: Configure your deployment environments. We usually have a "dev" and a "production"
|
|
18
|
+
# environment. Sometimes we have a "staging" or qa. You can do whatever you'd like.
|
|
19
|
+
|
|
20
|
+
Subspace.configure do |config|
|
|
21
|
+
# Project level configuration
|
|
22
|
+
|
|
23
|
+
# Name of the project. This will get used all over the place in path names, config file names, etc.
|
|
24
|
+
config.project_name = "<%= File.basename FileUtils.pwd =>"
|
|
25
|
+
|
|
26
|
+
# By default the name of the host and the group are the same for one-host groups
|
|
27
|
+
config.host :dev, {
|
|
28
|
+
ssh_host: "1.2.3.4", # Ansible connects to this to provision
|
|
29
|
+
ssh_user: "deploy", # ssh user
|
|
30
|
+
become: true, # probably should be true if user isn't root
|
|
31
|
+
hostname: "dev.example.com" # This will get set in /etc/hostname
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# Configuration for a group of hosts
|
|
36
|
+
# These hosts
|
|
37
|
+
config.group :dev, {
|
|
38
|
+
hosts: [:dev, :dev_web1],
|
|
39
|
+
vars: {
|
|
40
|
+
rails_env: "dev"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
config.group :production, {
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
# Configure the ansible roles that the project will use. This is where you can set up things like
|
|
48
|
+
# nginx vs apache, postgres vs mysql, etc. You can configure variables with each role or globally.
|
|
49
|
+
# In Ansible, all variables are global not scoped to a role, and you can override the defaults per-host or per-group.
|
|
50
|
+
# For convenience, we put all the default variables for each role in a block, but the following two lines have
|
|
51
|
+
# identical effect:
|
|
52
|
+
#
|
|
53
|
+
# config.role "myrole" {|vars| vars.option "new_value" }
|
|
54
|
+
# config.var :option. "new_value"
|
|
55
|
+
|
|
56
|
+
config.role "common", vars: {
|
|
57
|
+
# swap_space: 536870912,
|
|
58
|
+
# deploy_user: "deploy"
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
config.role "ruby-common", vars: {
|
|
62
|
+
# ruby_bundler_flags: "",
|
|
63
|
+
# ruby_free_min: "",
|
|
64
|
+
# ruby_gc_malloc_limit: "",
|
|
65
|
+
# ruby_heap_min_slots: ""
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
config.role "rails"
|
|
69
|
+
config.role "apache"
|
|
70
|
+
config.role "letsencrypt", groups: [:web], vars: {
|
|
71
|
+
certbot_dir: "/opt/certbot"
|
|
72
|
+
}
|
|
73
|
+
config.role "mtpereira.passenger"
|
|
74
|
+
config.role "postgresql", groups: [:db]
|
|
75
|
+
config.role "delayed_job", vars: {
|
|
76
|
+
delayed_job_command: "bin/delayed_job",
|
|
77
|
+
delayed_job_queues: ["default"]
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
config.role "logrotate"
|
|
81
|
+
# config.var :logrotate_scripts, [{
|
|
82
|
+
# name: "Rails Logs",
|
|
83
|
+
# path: "/u/apps/{{project_name}}/shared/log/*.log",
|
|
84
|
+
# options: [
|
|
85
|
+
# "weekly",
|
|
86
|
+
# "size 1M",
|
|
87
|
+
# "missingok",
|
|
88
|
+
# "compress",
|
|
89
|
+
# "delaycompress",
|
|
90
|
+
# "copytruncate",
|
|
91
|
+
# ]
|
|
92
|
+
# }]
|
|
93
|
+
|
|
94
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[defaults]
|
|
2
|
+
forks = 10
|
|
3
|
+
roles_path = ./roles:<%= File.join(gem_path, 'ansible', 'roles') %>:/etc/ansible/roles
|
|
4
|
+
vault_password_file = .vault_pass
|
|
5
|
+
inventory = inventory.yml
|
|
6
|
+
no_target_syslog = false
|
|
7
|
+
# Uncomment to add timestamps to tasks to find slow ones.
|
|
8
|
+
# callback_whitelist = profile_tasks
|
|
9
|
+
|
|
10
|
+
<% if @mitogen_path %>
|
|
11
|
+
strategy_plugins = <%= @mitogen_path %>/ansible_mitogen/plugins/strategy
|
|
12
|
+
strategy = mitogen_linear
|
|
13
|
+
<% end %>
|
|
14
|
+
|
|
15
|
+
[ssh_connection]
|
|
16
|
+
pipelining = True
|
|
17
|
+
control_path = /tmp/subspace-control-%%h-%%p-%%r
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Conventions and defaults are defined here
|
|
2
|
+
project_name: <%= project_name %>
|
|
3
|
+
database_host: localhost
|
|
4
|
+
use_sudo: true
|
|
5
|
+
|
|
6
|
+
# ruby-common
|
|
7
|
+
# pull the checksum/url from https://www.ruby-lang.org/en/downloads/
|
|
8
|
+
ruby_version: # ruby-2.7.1
|
|
9
|
+
ruby_checksum: # d418483bdd0000576c1370571121a6eb24582116db0b7bb2005e90e250eae418
|
|
10
|
+
ruby_download_location: # https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.1.tar.gz
|
|
11
|
+
bundler_version: # 2.3.5
|
|
12
|
+
|
|
13
|
+
# Other stuff
|
|
14
|
+
letsencrypt_email:
|
|
15
|
+
nodejs_version: # 16.x
|
|
16
|
+
ssl_enabled: true
|
|
17
|
+
postgresql_version: # 14
|
|
18
|
+
|
|
19
|
+
logrotate_scripts:
|
|
20
|
+
- name: rails
|
|
21
|
+
path: "/u/apps/{{project_name}}/shared/log/{{rails_env}}.log"
|
|
22
|
+
options:
|
|
23
|
+
- weekly
|
|
24
|
+
- size 100M
|
|
25
|
+
- missingok
|
|
26
|
+
- compress
|
|
27
|
+
- delaycompress
|
|
28
|
+
- copytruncate
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
## rails
|
|
2
|
+
rails_env: <%= @env %>
|
|
3
|
+
|
|
4
|
+
database_pool: 5
|
|
5
|
+
database_name: "{{project_name}}_{{rails_env}}"
|
|
6
|
+
database_user: "{{project_name}}"
|
|
7
|
+
database_adapter: postgresql
|
|
8
|
+
# job_queues:
|
|
9
|
+
# - default
|
|
10
|
+
# - mailers
|
|
11
|
+
|
|
12
|
+
# nginx / letsencrypt
|
|
13
|
+
server_name: "{{ansible_host}}"
|
|
14
|
+
|
|
15
|
+
## postgresql
|
|
16
|
+
# postgresql_version: 14
|
|
17
|
+
# postgresql_authentication:
|
|
18
|
+
# - type: local
|
|
19
|
+
# user: "{{database_user}}"
|
|
20
|
+
# database: 'all'
|
|
21
|
+
# method: trust
|
|
22
|
+
|
|
23
|
+
## puma
|
|
24
|
+
puma_workers: 1
|
|
25
|
+
puma_min_threads: 4
|
|
26
|
+
puma_max_threads: 16
|