wombat-cli 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +23 -23
- data/.travis.yml +22 -27
- data/CHANGELOG.md +438 -423
- data/DESIGN.md +49 -49
- data/Gemfile +5 -5
- data/README.md +146 -146
- data/Rakefile +26 -26
- data/bin/wombat +24 -24
- data/generator_files/Vagrantfile +120 -120
- data/generator_files/cookbooks/automate/.gitignore +16 -16
- data/generator_files/cookbooks/automate/.kitchen.ec2.yml +34 -34
- data/generator_files/cookbooks/automate/.kitchen.yml +24 -24
- data/generator_files/cookbooks/automate/Berksfile +6 -6
- data/generator_files/cookbooks/automate/README.md +4 -4
- data/generator_files/cookbooks/automate/chefignore +102 -102
- data/generator_files/cookbooks/automate/libraries/_helper.rb +52 -52
- data/generator_files/cookbooks/automate/libraries/delivery_api.rb +204 -204
- data/generator_files/cookbooks/automate/libraries/delivery_project.rb +31 -31
- data/generator_files/cookbooks/automate/libraries/dsl.rb +4 -4
- data/generator_files/cookbooks/automate/metadata.rb +11 -11
- data/generator_files/cookbooks/automate/recipes/default.rb +118 -124
- data/generator_files/cookbooks/automate/recipes/update-users.rb +48 -48
- data/generator_files/cookbooks/automate/templates/delivery.erb +6 -6
- data/generator_files/cookbooks/automate/test/fixtures/cookbooks/mock_data/files/automate.crt +26 -26
- data/generator_files/cookbooks/automate/test/fixtures/cookbooks/mock_data/files/automate.key +27 -27
- data/generator_files/cookbooks/automate/test/fixtures/cookbooks/mock_data/files/chef.crt +25 -25
- data/generator_files/cookbooks/automate/test/fixtures/cookbooks/mock_data/files/chef.key +27 -27
- data/generator_files/cookbooks/automate/test/fixtures/cookbooks/mock_data/files/compliance.crt +26 -26
- data/generator_files/cookbooks/automate/test/fixtures/cookbooks/mock_data/files/compliance.key +27 -27
- data/generator_files/cookbooks/automate/test/fixtures/cookbooks/mock_data/files/private.pem +27 -27
- data/generator_files/cookbooks/automate/test/fixtures/cookbooks/mock_data/files/public.pub +1 -1
- data/generator_files/cookbooks/automate/test/fixtures/cookbooks/mock_data/metadata.rb +3 -3
- data/generator_files/cookbooks/automate/test/fixtures/cookbooks/mock_data/recipes/default.rb +27 -27
- data/generator_files/cookbooks/automate/test/integration/default/automate_spec.rb +56 -56
- data/generator_files/cookbooks/build_node/.gitignore +16 -16
- data/generator_files/cookbooks/build_node/.kitchen.ec2.yml +37 -37
- data/generator_files/cookbooks/build_node/.kitchen.yml +23 -23
- data/generator_files/cookbooks/build_node/Berksfile +8 -8
- data/generator_files/cookbooks/build_node/README.md +4 -4
- data/generator_files/cookbooks/build_node/chefignore +102 -102
- data/generator_files/cookbooks/build_node/metadata.rb +12 -12
- data/generator_files/cookbooks/build_node/recipes/default.rb +38 -38
- data/generator_files/cookbooks/build_node/templates/client.erb +2 -2
- data/generator_files/cookbooks/build_node/test/fixtures/cookbooks/mock_data/files/automate.crt +26 -26
- data/generator_files/cookbooks/build_node/test/fixtures/cookbooks/mock_data/files/automate.key +27 -27
- data/generator_files/cookbooks/build_node/test/fixtures/cookbooks/mock_data/files/chef.crt +25 -25
- data/generator_files/cookbooks/build_node/test/fixtures/cookbooks/mock_data/files/chef.key +27 -27
- data/generator_files/cookbooks/build_node/test/fixtures/cookbooks/mock_data/files/compliance.crt +26 -26
- data/generator_files/cookbooks/build_node/test/fixtures/cookbooks/mock_data/files/compliance.key +27 -27
- data/generator_files/cookbooks/build_node/test/fixtures/cookbooks/mock_data/files/private.pem +27 -27
- data/generator_files/cookbooks/build_node/test/fixtures/cookbooks/mock_data/files/public.pub +1 -1
- data/generator_files/cookbooks/build_node/test/fixtures/cookbooks/mock_data/metadata.rb +2 -2
- data/generator_files/cookbooks/build_node/test/fixtures/cookbooks/mock_data/recipes/default.rb +18 -18
- data/generator_files/cookbooks/build_node/test/integration/default/build-node_spec.rb +40 -40
- data/generator_files/cookbooks/chef_server/.gitignore +16 -16
- data/generator_files/cookbooks/chef_server/.kitchen.ec2.yml +34 -34
- data/generator_files/cookbooks/chef_server/.kitchen.yml +24 -24
- data/generator_files/cookbooks/chef_server/Berksfile +6 -6
- data/generator_files/cookbooks/chef_server/README.md +4 -4
- data/generator_files/cookbooks/chef_server/chefignore +102 -102
- data/generator_files/cookbooks/chef_server/metadata.rb +11 -11
- data/generator_files/cookbooks/chef_server/recipes/bootstrap_users.rb +91 -91
- data/generator_files/cookbooks/chef_server/recipes/default.rb +113 -113
- data/generator_files/cookbooks/chef_server/test/fixtures/cookbooks/mock_data/files/automate.crt +26 -26
- data/generator_files/cookbooks/chef_server/test/fixtures/cookbooks/mock_data/files/automate.key +27 -27
- data/generator_files/cookbooks/chef_server/test/fixtures/cookbooks/mock_data/files/chef.crt +25 -25
- data/generator_files/cookbooks/chef_server/test/fixtures/cookbooks/mock_data/files/chef.key +27 -27
- data/generator_files/cookbooks/chef_server/test/fixtures/cookbooks/mock_data/files/compliance.crt +26 -26
- data/generator_files/cookbooks/chef_server/test/fixtures/cookbooks/mock_data/files/compliance.key +27 -27
- data/generator_files/cookbooks/chef_server/test/fixtures/cookbooks/mock_data/files/private.pem +27 -27
- data/generator_files/cookbooks/chef_server/test/fixtures/cookbooks/mock_data/files/public.pub +1 -1
- data/generator_files/cookbooks/chef_server/test/fixtures/cookbooks/mock_data/metadata.rb +2 -2
- data/generator_files/cookbooks/chef_server/test/fixtures/cookbooks/mock_data/recipes/default.rb +23 -23
- data/generator_files/cookbooks/chef_server/test/integration/default/chef_server_spec.rb +50 -50
- data/generator_files/cookbooks/compliance/.gitignore +16 -16
- data/generator_files/cookbooks/compliance/.kitchen.ec2.yml +34 -34
- data/generator_files/cookbooks/compliance/.kitchen.yml +24 -24
- data/generator_files/cookbooks/compliance/Berksfile +7 -7
- data/generator_files/cookbooks/compliance/README.md +4 -4
- data/generator_files/cookbooks/compliance/chefignore +102 -102
- data/generator_files/cookbooks/compliance/metadata.rb +11 -11
- data/generator_files/cookbooks/compliance/recipes/default.rb +57 -57
- data/generator_files/cookbooks/compliance/spec/spec_helper.rb +2 -2
- data/generator_files/cookbooks/compliance/spec/unit/recipes/default_spec.rb +20 -20
- data/generator_files/cookbooks/compliance/test/fixtures/cookbooks/mock_data/files/automate.crt +26 -26
- data/generator_files/cookbooks/compliance/test/fixtures/cookbooks/mock_data/files/automate.key +27 -27
- data/generator_files/cookbooks/compliance/test/fixtures/cookbooks/mock_data/files/chef.crt +25 -25
- data/generator_files/cookbooks/compliance/test/fixtures/cookbooks/mock_data/files/chef.key +27 -27
- data/generator_files/cookbooks/compliance/test/fixtures/cookbooks/mock_data/files/compliance.crt +26 -26
- data/generator_files/cookbooks/compliance/test/fixtures/cookbooks/mock_data/files/compliance.key +27 -27
- data/generator_files/cookbooks/compliance/test/fixtures/cookbooks/mock_data/files/private.pem +27 -27
- data/generator_files/cookbooks/compliance/test/fixtures/cookbooks/mock_data/files/public.pub +1 -1
- data/generator_files/cookbooks/compliance/test/fixtures/cookbooks/mock_data/metadata.rb +4 -4
- data/generator_files/cookbooks/compliance/test/fixtures/cookbooks/mock_data/recipes/default.rb +21 -21
- data/generator_files/cookbooks/compliance/test/integration/default/compliance.rb +28 -28
- data/generator_files/cookbooks/infranodes/.gitignore +16 -16
- data/generator_files/cookbooks/infranodes/.kitchen.ec2.yml +48 -48
- data/generator_files/cookbooks/infranodes/.kitchen.yml +21 -21
- data/generator_files/cookbooks/infranodes/Berksfile +6 -6
- data/generator_files/cookbooks/infranodes/README.md +4 -4
- data/generator_files/cookbooks/infranodes/attributes/default.rb +2 -2
- data/generator_files/cookbooks/infranodes/chefignore +102 -102
- data/generator_files/cookbooks/infranodes/metadata.rb +13 -13
- data/generator_files/cookbooks/infranodes/recipes/default.rb +57 -57
- data/generator_files/cookbooks/infranodes/spec/spec_helper.rb +2 -2
- data/generator_files/cookbooks/infranodes/spec/unit/recipes/default_spec.rb +20 -20
- data/generator_files/cookbooks/infranodes/templates/default/client.rb.erb +5 -5
- data/generator_files/cookbooks/infranodes/test/fixtures/cookbooks/mock_data/files/automate.crt +26 -26
- data/generator_files/cookbooks/infranodes/test/fixtures/cookbooks/mock_data/files/automate.key +27 -27
- data/generator_files/cookbooks/infranodes/test/fixtures/cookbooks/mock_data/files/chef.crt +25 -25
- data/generator_files/cookbooks/infranodes/test/fixtures/cookbooks/mock_data/files/chef.key +27 -27
- data/generator_files/cookbooks/infranodes/test/fixtures/cookbooks/mock_data/files/compliance.crt +26 -26
- data/generator_files/cookbooks/infranodes/test/fixtures/cookbooks/mock_data/files/compliance.key +27 -27
- data/generator_files/cookbooks/infranodes/test/fixtures/cookbooks/mock_data/files/private.pem +27 -27
- data/generator_files/cookbooks/infranodes/test/fixtures/cookbooks/mock_data/files/public.pub +1 -1
- data/generator_files/cookbooks/infranodes/test/fixtures/cookbooks/mock_data/metadata.rb +3 -3
- data/generator_files/cookbooks/infranodes/test/fixtures/cookbooks/mock_data/recipes/default.rb +27 -27
- data/generator_files/cookbooks/infranodes/test/integration/default/infranodes_spec.rb +22 -22
- data/generator_files/cookbooks/infranodes/test/integration/helpers/serverspec/spec_helper.rb +8 -8
- data/generator_files/cookbooks/wombat/.gitignore +16 -16
- data/generator_files/cookbooks/wombat/.kitchen.yml +43 -43
- data/generator_files/cookbooks/wombat/Berksfile +5 -5
- data/generator_files/cookbooks/wombat/README.md +4 -4
- data/generator_files/cookbooks/wombat/attributes/default.rb +79 -80
- data/generator_files/cookbooks/wombat/attributes/packer.rb +18 -18
- data/generator_files/cookbooks/wombat/chefignore +102 -102
- data/generator_files/cookbooks/wombat/metadata.rb +13 -13
- data/generator_files/cookbooks/wombat/recipes/authorized-keys.rb +20 -20
- data/generator_files/cookbooks/wombat/recipes/default.rb +111 -111
- data/generator_files/cookbooks/wombat/recipes/etc-hosts.rb +51 -51
- data/generator_files/cookbooks/workstation/.gitignore +16 -16
- data/generator_files/cookbooks/workstation/.kitchen.azure.yml +45 -0
- data/generator_files/cookbooks/workstation/.kitchen.ec2.yml +46 -30
- data/generator_files/cookbooks/workstation/.kitchen.yml +42 -22
- data/generator_files/cookbooks/workstation/Berksfile +7 -7
- data/generator_files/cookbooks/workstation/README.md +3 -3
- data/generator_files/cookbooks/workstation/chefignore +106 -102
- data/generator_files/cookbooks/workstation/files/atom.apm.list +10 -7
- data/generator_files/cookbooks/workstation/files/atom.config.cson +6 -3
- data/generator_files/cookbooks/workstation/{templates/default/ise_profile.ps1.erb → files/ise_profile.ps1} +11 -11
- data/generator_files/cookbooks/workstation/libraries/home.rb +4 -4
- data/generator_files/cookbooks/workstation/metadata.rb +14 -14
- data/generator_files/cookbooks/workstation/recipes/browser.rb +53 -58
- data/generator_files/cookbooks/workstation/recipes/certs-keys.rb +41 -45
- data/generator_files/cookbooks/workstation/recipes/chef.rb +29 -28
- data/generator_files/cookbooks/workstation/recipes/default.rb +24 -21
- data/generator_files/cookbooks/workstation/recipes/dotnet.rb +19 -17
- data/generator_files/cookbooks/workstation/recipes/editor.rb +46 -18
- data/generator_files/cookbooks/workstation/recipes/profile.rb +14 -41
- data/generator_files/cookbooks/workstation/recipes/terminal.rb +11 -11
- data/generator_files/cookbooks/workstation/templates/default/bookmarks.html.erb +23 -23
- data/generator_files/cookbooks/workstation/templates/default/data_collector.rb.erb +2 -2
- data/generator_files/cookbooks/workstation/templates/default/knife.rb.erb +10 -10
- data/generator_files/cookbooks/workstation/templates/default/master_preferences.json.erb +28 -28
- data/generator_files/cookbooks/workstation/templates/default/ssh_config.erb +16 -16
- data/generator_files/cookbooks/workstation/test/fixtures/cookbooks/mock_data/files/automate.crt +26 -26
- data/generator_files/cookbooks/workstation/test/fixtures/cookbooks/mock_data/files/automate.key +27 -27
- data/generator_files/cookbooks/workstation/test/fixtures/cookbooks/mock_data/files/chef.crt +26 -26
- data/generator_files/cookbooks/workstation/test/fixtures/cookbooks/mock_data/files/chef.key +27 -27
- data/generator_files/cookbooks/workstation/test/fixtures/cookbooks/mock_data/files/compliance.crt +26 -26
- data/generator_files/cookbooks/workstation/test/fixtures/cookbooks/mock_data/files/compliance.key +27 -27
- data/generator_files/cookbooks/workstation/test/fixtures/cookbooks/mock_data/files/private.pem +27 -27
- data/generator_files/cookbooks/workstation/test/fixtures/cookbooks/mock_data/files/public.pub +1 -1
- data/generator_files/cookbooks/workstation/test/fixtures/cookbooks/mock_data/metadata.rb +2 -2
- data/generator_files/cookbooks/workstation/test/fixtures/cookbooks/mock_data/recipes/default.rb +21 -21
- data/generator_files/cookbooks/workstation/test/integration/default/workstation_spec.rb +77 -37
- data/generator_files/packer/automate.json +136 -136
- data/generator_files/packer/build-node.json +142 -142
- data/generator_files/packer/chef-server.json +137 -137
- data/generator_files/packer/compliance.json +133 -133
- data/generator_files/packer/infranodes-windows.json +143 -143
- data/generator_files/packer/infranodes.json +134 -134
- data/generator_files/packer/scripts/PreSysprep.ps1 +9 -0
- data/generator_files/packer/workstation.json +160 -142
- data/generator_files/templates/arm.md.json.erb +754 -754
- data/generator_files/templates/arm.vhd.json.erb +630 -630
- data/generator_files/templates/bootstrap-aws.erb +39 -39
- data/generator_files/templates/cfn.json.erb +675 -674
- data/generator_files/wombat.yml +75 -74
- data/lib/wombat/aws.rb +67 -67
- data/lib/wombat/build.rb +392 -392
- data/lib/wombat/cli.rb +254 -254
- data/lib/wombat/common.rb +420 -420
- data/lib/wombat/crypto.rb +65 -65
- data/lib/wombat/delete.rb +67 -67
- data/lib/wombat/deploy.rb +128 -128
- data/lib/wombat/init.rb +32 -32
- data/lib/wombat/latest.rb +27 -27
- data/lib/wombat/output.rb +101 -101
- data/lib/wombat/update.rb +20 -20
- data/lib/wombat/version.rb +3 -3
- data/lib/wombat.rb +8 -8
- data/spec/functional/common_spec.rb +26 -26
- data/spec/spec_helper.rb +103 -103
- data/spec/unit/common_spec.rb +116 -116
- data/terraform/README.md +13 -13
- data/terraform/templates/terraform.tfvars.erb +12 -12
- data/terraform/wombat.tf +328 -328
- data/wombat-cli.gemspec +36 -36
- metadata +6 -4
data/lib/wombat/crypto.rb
CHANGED
@@ -1,66 +1,66 @@
|
|
1
|
-
require 'openssl'
|
2
|
-
require 'net/ssh'
|
3
|
-
|
4
|
-
module Wombat
|
5
|
-
module Crypto
|
6
|
-
include Wombat::Common
|
7
|
-
|
8
|
-
def gen_x509_cert(hostname)
|
9
|
-
rsa_key = OpenSSL::PKey::RSA.new(2048)
|
10
|
-
public_key = rsa_key.public_key
|
11
|
-
|
12
|
-
subject = "/C=AU/ST=New South Wales/L=Sydney/O=#{wombat['org']}/OU=wombats/CN=#{wombat['domain_prefix']}#{hostname}.#{wombat['domain']}"
|
13
|
-
|
14
|
-
cert = OpenSSL::X509::Certificate.new
|
15
|
-
cert.subject = cert.issuer = OpenSSL::X509::Name.parse(subject)
|
16
|
-
cert.not_before = Time.now
|
17
|
-
cert.not_after = Time.now + 365 * 24 * 60 * 60
|
18
|
-
cert.public_key = public_key
|
19
|
-
cert.serial = 0x0
|
20
|
-
cert.version = 2
|
21
|
-
|
22
|
-
ef = OpenSSL::X509::ExtensionFactory.new
|
23
|
-
ef.subject_certificate = cert
|
24
|
-
ef.issuer_certificate = cert
|
25
|
-
cert.extensions = [
|
26
|
-
ef.create_extension('basicConstraints', 'CA:TRUE', true),
|
27
|
-
ef.create_extension('subjectKeyIdentifier', 'hash'),
|
28
|
-
ef.create_extension('subjectAltName', "DNS:#{wombat['domain_prefix']}#{hostname}.#{wombat['domain']},DNS:#{hostname}"),
|
29
|
-
# ef.create_extension("keyUsage", "cRLSign,keyCertSign", true),
|
30
|
-
]
|
31
|
-
cert.add_extension ef.create_extension('authorityKeyIdentifier',
|
32
|
-
'keyid:always,issuer:always')
|
33
|
-
|
34
|
-
cert.sign(rsa_key, OpenSSL::Digest::SHA256.new)
|
35
|
-
|
36
|
-
Dir.mkdir(conf['key_dir'], 0755) unless File.exist?(conf['key_dir'])
|
37
|
-
|
38
|
-
if File.exist?("#{conf['key_dir']}/#{hostname}.crt") && File.exist?("#{conf['key_dir']}/#{hostname}.key")
|
39
|
-
puts "An x509 certificate already exists for #{hostname}"
|
40
|
-
else
|
41
|
-
File.open("#{conf['key_dir']}/#{hostname}.crt", 'w') { |file| file.puts cert.to_pem }
|
42
|
-
File.open("#{conf['key_dir']}/#{hostname}.key", 'w') { |file| file.puts rsa_key.to_pem }
|
43
|
-
puts "Certificate created for #{wombat['domain_prefix']}#{hostname}.#{wombat['domain']}"
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def gen_ssh_key
|
48
|
-
rsa_key = OpenSSL::PKey::RSA.new 2048
|
49
|
-
|
50
|
-
type = rsa_key.ssh_type
|
51
|
-
data = [rsa_key.to_blob].pack('m0')
|
52
|
-
|
53
|
-
openssh_format = "#{type} #{data}"
|
54
|
-
|
55
|
-
Dir.mkdir(conf['key_dir'], 0755) unless File.exist?(conf['key_dir'])
|
56
|
-
|
57
|
-
if File.exist?("#{conf['key_dir']}/public.pub") && File.exist?("#{conf['key_dir']}/private.pem")
|
58
|
-
puts 'An SSH keypair already exists'
|
59
|
-
else
|
60
|
-
File.open("#{conf['key_dir']}/public.pub", 'w') { |file| file.puts openssh_format }
|
61
|
-
File.open("#{conf['key_dir']}/private.pem", 'w') { |file| file.puts rsa_key.to_pem }
|
62
|
-
puts 'SSH Keypair created'
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
1
|
+
require 'openssl'
|
2
|
+
require 'net/ssh'
|
3
|
+
|
4
|
+
module Wombat
|
5
|
+
module Crypto
|
6
|
+
include Wombat::Common
|
7
|
+
|
8
|
+
def gen_x509_cert(hostname)
|
9
|
+
rsa_key = OpenSSL::PKey::RSA.new(2048)
|
10
|
+
public_key = rsa_key.public_key
|
11
|
+
|
12
|
+
subject = "/C=AU/ST=New South Wales/L=Sydney/O=#{wombat['org']}/OU=wombats/CN=#{wombat['domain_prefix']}#{hostname}.#{wombat['domain']}"
|
13
|
+
|
14
|
+
cert = OpenSSL::X509::Certificate.new
|
15
|
+
cert.subject = cert.issuer = OpenSSL::X509::Name.parse(subject)
|
16
|
+
cert.not_before = Time.now
|
17
|
+
cert.not_after = Time.now + 365 * 24 * 60 * 60
|
18
|
+
cert.public_key = public_key
|
19
|
+
cert.serial = 0x0
|
20
|
+
cert.version = 2
|
21
|
+
|
22
|
+
ef = OpenSSL::X509::ExtensionFactory.new
|
23
|
+
ef.subject_certificate = cert
|
24
|
+
ef.issuer_certificate = cert
|
25
|
+
cert.extensions = [
|
26
|
+
ef.create_extension('basicConstraints', 'CA:TRUE', true),
|
27
|
+
ef.create_extension('subjectKeyIdentifier', 'hash'),
|
28
|
+
ef.create_extension('subjectAltName', "DNS:#{wombat['domain_prefix']}#{hostname}.#{wombat['domain']},DNS:#{hostname}"),
|
29
|
+
# ef.create_extension("keyUsage", "cRLSign,keyCertSign", true),
|
30
|
+
]
|
31
|
+
cert.add_extension ef.create_extension('authorityKeyIdentifier',
|
32
|
+
'keyid:always,issuer:always')
|
33
|
+
|
34
|
+
cert.sign(rsa_key, OpenSSL::Digest::SHA256.new)
|
35
|
+
|
36
|
+
Dir.mkdir(conf['key_dir'], 0755) unless File.exist?(conf['key_dir'])
|
37
|
+
|
38
|
+
if File.exist?("#{conf['key_dir']}/#{hostname}.crt") && File.exist?("#{conf['key_dir']}/#{hostname}.key")
|
39
|
+
puts "An x509 certificate already exists for #{hostname}"
|
40
|
+
else
|
41
|
+
File.open("#{conf['key_dir']}/#{hostname}.crt", 'w') { |file| file.puts cert.to_pem }
|
42
|
+
File.open("#{conf['key_dir']}/#{hostname}.key", 'w') { |file| file.puts rsa_key.to_pem }
|
43
|
+
puts "Certificate created for #{wombat['domain_prefix']}#{hostname}.#{wombat['domain']}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def gen_ssh_key
|
48
|
+
rsa_key = OpenSSL::PKey::RSA.new 2048
|
49
|
+
|
50
|
+
type = rsa_key.ssh_type
|
51
|
+
data = [rsa_key.to_blob].pack('m0')
|
52
|
+
|
53
|
+
openssh_format = "#{type} #{data}"
|
54
|
+
|
55
|
+
Dir.mkdir(conf['key_dir'], 0755) unless File.exist?(conf['key_dir'])
|
56
|
+
|
57
|
+
if File.exist?("#{conf['key_dir']}/public.pub") && File.exist?("#{conf['key_dir']}/private.pem")
|
58
|
+
puts 'An SSH keypair already exists'
|
59
|
+
else
|
60
|
+
File.open("#{conf['key_dir']}/public.pub", 'w') { |file| file.puts openssh_format }
|
61
|
+
File.open("#{conf['key_dir']}/private.pem", 'w') { |file| file.puts rsa_key.to_pem }
|
62
|
+
puts 'SSH Keypair created'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
66
|
end
|
data/lib/wombat/delete.rb
CHANGED
@@ -1,68 +1,68 @@
|
|
1
|
-
require 'wombat/common'
|
2
|
-
require 'aws-sdk'
|
3
|
-
require 'azure_mgmt_resources'
|
4
|
-
|
5
|
-
module Wombat
|
6
|
-
class DeleteRunner
|
7
|
-
include Wombat::Common
|
8
|
-
|
9
|
-
attr_reader :stack, :cloud
|
10
|
-
attr_accessor :resource_management_client
|
11
|
-
|
12
|
-
def initialize(opts)
|
13
|
-
@stack = opts.stack
|
14
|
-
@cloud = opts.cloud.nil? ? "aws" : opts.cloud
|
15
|
-
@force = opts.force.nil? ? false : opts.force
|
16
|
-
@azure_async = opts.azure_async.nil? ? false : opts.azure_async
|
17
|
-
@wombat_yml = opts.wombat_yml unless opts.wombat_yml.nil?
|
18
|
-
end
|
19
|
-
|
20
|
-
def start
|
21
|
-
cfn_delete_stack(stack)
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def cfn_delete_stack(stack)
|
27
|
-
|
28
|
-
# Delete the stack from the correct platform
|
29
|
-
case @cloud
|
30
|
-
when "aws"
|
31
|
-
cfn = ::Aws::CloudFormation::Client.new(region: lock['aws']['region'])
|
32
|
-
|
33
|
-
resp = cfn.delete_stack({
|
34
|
-
stack_name: stack,
|
35
|
-
})
|
36
|
-
banner("Deleted #{stack}")
|
37
|
-
|
38
|
-
when "azure"
|
39
|
-
|
40
|
-
# Configure the delete state
|
41
|
-
delete = false
|
42
|
-
|
43
|
-
# Connect to Azure
|
44
|
-
azure_conn = connect_azure()
|
45
|
-
|
46
|
-
# Create a resource client so that the resource group can be deleted
|
47
|
-
@resource_management_client = ::Azure::ARM::Resources::ResourceManagementClient.new(azure_conn)
|
48
|
-
@resource_management_client.subscription_id = ENV['AZURE_SUBSCRIPTION_ID']
|
49
|
-
|
50
|
-
# Check the stack that is being requested
|
51
|
-
# If it is the parent group display a warning before attempting to delete
|
52
|
-
if stack == wombat['name'] && !@force
|
53
|
-
warn("You are attempting to delete the resource group that contains your custom images. If you wish to do this please specify the --force parameter on the command")
|
54
|
-
else
|
55
|
-
delete = true
|
56
|
-
end
|
57
|
-
|
58
|
-
if (delete)
|
59
|
-
banner(format("Deleting resource group: %s", stack))
|
60
|
-
|
61
|
-
resource_management_client.resource_groups.begin_delete(stack)
|
62
|
-
|
63
|
-
info "Destroy operation accepted and will continue in the background."
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
1
|
+
require 'wombat/common'
|
2
|
+
require 'aws-sdk'
|
3
|
+
require 'azure_mgmt_resources'
|
4
|
+
|
5
|
+
module Wombat
|
6
|
+
class DeleteRunner
|
7
|
+
include Wombat::Common
|
8
|
+
|
9
|
+
attr_reader :stack, :cloud
|
10
|
+
attr_accessor :resource_management_client
|
11
|
+
|
12
|
+
def initialize(opts)
|
13
|
+
@stack = opts.stack
|
14
|
+
@cloud = opts.cloud.nil? ? "aws" : opts.cloud
|
15
|
+
@force = opts.force.nil? ? false : opts.force
|
16
|
+
@azure_async = opts.azure_async.nil? ? false : opts.azure_async
|
17
|
+
@wombat_yml = opts.wombat_yml unless opts.wombat_yml.nil?
|
18
|
+
end
|
19
|
+
|
20
|
+
def start
|
21
|
+
cfn_delete_stack(stack)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def cfn_delete_stack(stack)
|
27
|
+
|
28
|
+
# Delete the stack from the correct platform
|
29
|
+
case @cloud
|
30
|
+
when "aws"
|
31
|
+
cfn = ::Aws::CloudFormation::Client.new(region: lock['aws']['region'])
|
32
|
+
|
33
|
+
resp = cfn.delete_stack({
|
34
|
+
stack_name: stack,
|
35
|
+
})
|
36
|
+
banner("Deleted #{stack}")
|
37
|
+
|
38
|
+
when "azure"
|
39
|
+
|
40
|
+
# Configure the delete state
|
41
|
+
delete = false
|
42
|
+
|
43
|
+
# Connect to Azure
|
44
|
+
azure_conn = connect_azure()
|
45
|
+
|
46
|
+
# Create a resource client so that the resource group can be deleted
|
47
|
+
@resource_management_client = ::Azure::ARM::Resources::ResourceManagementClient.new(azure_conn)
|
48
|
+
@resource_management_client.subscription_id = ENV['AZURE_SUBSCRIPTION_ID']
|
49
|
+
|
50
|
+
# Check the stack that is being requested
|
51
|
+
# If it is the parent group display a warning before attempting to delete
|
52
|
+
if stack == wombat['name'] && !@force
|
53
|
+
warn("You are attempting to delete the resource group that contains your custom images. If you wish to do this please specify the --force parameter on the command")
|
54
|
+
else
|
55
|
+
delete = true
|
56
|
+
end
|
57
|
+
|
58
|
+
if (delete)
|
59
|
+
banner(format("Deleting resource group: %s", stack))
|
60
|
+
|
61
|
+
resource_management_client.resource_groups.begin_delete(stack)
|
62
|
+
|
63
|
+
info "Destroy operation accepted and will continue in the background."
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
68
|
end
|
data/lib/wombat/deploy.rb
CHANGED
@@ -1,128 +1,128 @@
|
|
1
|
-
require 'wombat/common'
|
2
|
-
require 'aws-sdk'
|
3
|
-
require 'azure_mgmt_resources'
|
4
|
-
|
5
|
-
module Wombat
|
6
|
-
class DeployRunner
|
7
|
-
include Wombat::Common
|
8
|
-
|
9
|
-
attr_reader :stack, :stack_name, :cloud, :lock_opt, :template_opt, :nosuffix
|
10
|
-
attr_accessor :resource_management_client
|
11
|
-
|
12
|
-
def initialize(opts)
|
13
|
-
@stack = opts.stack
|
14
|
-
@stack_name = opts.stack_name
|
15
|
-
@cloud = opts.cloud.nil? ? "aws" : opts.cloud
|
16
|
-
@lock_opt = opts.update_lock
|
17
|
-
@template_opt = opts.update_template
|
18
|
-
@azure_async = opts.azure_async
|
19
|
-
@wombat_yml = opts.wombat_yml
|
20
|
-
@nosuffix = opts.nosuffix.nil? ? false : true
|
21
|
-
end
|
22
|
-
|
23
|
-
def start
|
24
|
-
update_lock(cloud) if lock_opt
|
25
|
-
update_template(cloud) if template_opt
|
26
|
-
create_stack(stack)
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def create_stack(stack)
|
32
|
-
|
33
|
-
# determine the filename of the stack
|
34
|
-
filename = stack
|
35
|
-
|
36
|
-
# work out the name of the stack to be created
|
37
|
-
if !@stack_name.nil?
|
38
|
-
|
39
|
-
# As the stack name has been specified then set nosuffix
|
40
|
-
@nosuffix = true
|
41
|
-
stack = stack_name
|
42
|
-
end
|
43
|
-
|
44
|
-
# Deploy the template to the correct stack
|
45
|
-
case @cloud
|
46
|
-
when "aws"
|
47
|
-
|
48
|
-
template_file = File.read("#{conf['stack_dir']}/#{filename}.json")
|
49
|
-
cfn = ::Aws::CloudFormation::Client.new(region: lock['aws']['region'])
|
50
|
-
|
51
|
-
banner("Creating CloudFormation stack")
|
52
|
-
resp = cfn.create_stack({
|
53
|
-
stack_name: "#{stack}",
|
54
|
-
template_body: template_file,
|
55
|
-
capabilities: ["CAPABILITY_IAM"],
|
56
|
-
on_failure: "DELETE",
|
57
|
-
parameters: [
|
58
|
-
{
|
59
|
-
parameter_key: "KeyName",
|
60
|
-
parameter_value: lock['aws']['keypair'],
|
61
|
-
}
|
62
|
-
]
|
63
|
-
})
|
64
|
-
puts "Created: #{resp.stack_id}"
|
65
|
-
when "azure"
|
66
|
-
|
67
|
-
banner("Creating Azure RM stack")
|
68
|
-
|
69
|
-
# determine the path to the arm template
|
70
|
-
template_file = File.read("#{conf['stack_dir']}/#{filename}.json")
|
71
|
-
|
72
|
-
# determine the name of the deployment
|
73
|
-
deployment_name = format('deploy-%s', Time.now().to_i)
|
74
|
-
|
75
|
-
# determine the name of the resource group
|
76
|
-
resource_group_name = stack
|
77
|
-
if !nosuffix
|
78
|
-
resource_group_name = format('%s-%s', resource_group_name, Time.now.strftime('%Y%m%d%H%M%S'))
|
79
|
-
end
|
80
|
-
|
81
|
-
# Connect to azure
|
82
|
-
azure_conn = connect_azure()
|
83
|
-
|
84
|
-
# Create a resource client so that the template can be deployed
|
85
|
-
@resource_management_client = Azure::ARM::Resources::ResourceManagementClient.new(azure_conn)
|
86
|
-
@resource_management_client.subscription_id = ENV['AZURE_SUBSCRIPTION_ID']
|
87
|
-
|
88
|
-
# Create the resource group for the deployment
|
89
|
-
create_resource_group(resource_management_client,
|
90
|
-
resource_group_name,
|
91
|
-
wombat['azure']['location'],
|
92
|
-
wombat['owner'],
|
93
|
-
wombat['azure']['tags'])
|
94
|
-
|
95
|
-
# Create the deployment definition
|
96
|
-
deployment = Azure::ARM::Resources::Models::Deployment.new
|
97
|
-
deployment.properties = Azure::ARM::Resources::Models::DeploymentProperties.new
|
98
|
-
deployment.properties.mode = Azure::ARM::Resources::Models::DeploymentMode::Incremental
|
99
|
-
deployment.properties.template = JSON.parse(template_file)
|
100
|
-
|
101
|
-
# Perform the deployment to the named resource group
|
102
|
-
begin
|
103
|
-
resource_management_client.deployments.begin_create_or_update_async(resource_group_name, deployment_name, deployment).value!
|
104
|
-
rescue MsRestAzure::AzureOperationError => operation_error
|
105
|
-
rest_error = operation_error.body['error']
|
106
|
-
deployment_active = rest_error['code'] == 'DeploymentActive'
|
107
|
-
if deployment_active
|
108
|
-
info format("Deployment for resource group '%s' is ongoing", resource_group_name)
|
109
|
-
else
|
110
|
-
warn rest_error
|
111
|
-
raise operation_error
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
# Monitor the deployment
|
116
|
-
if @azure_async
|
117
|
-
info "Deployment operation accepted. Use the Azure Portal to check progress"
|
118
|
-
else
|
119
|
-
follow_azure_deployment(resource_group_name, deployment_name)
|
120
|
-
end
|
121
|
-
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
end
|
128
|
-
end
|
1
|
+
require 'wombat/common'
|
2
|
+
require 'aws-sdk'
|
3
|
+
require 'azure_mgmt_resources'
|
4
|
+
|
5
|
+
module Wombat
|
6
|
+
class DeployRunner
|
7
|
+
include Wombat::Common
|
8
|
+
|
9
|
+
attr_reader :stack, :stack_name, :cloud, :lock_opt, :template_opt, :nosuffix
|
10
|
+
attr_accessor :resource_management_client
|
11
|
+
|
12
|
+
def initialize(opts)
|
13
|
+
@stack = opts.stack
|
14
|
+
@stack_name = opts.stack_name
|
15
|
+
@cloud = opts.cloud.nil? ? "aws" : opts.cloud
|
16
|
+
@lock_opt = opts.update_lock
|
17
|
+
@template_opt = opts.update_template
|
18
|
+
@azure_async = opts.azure_async
|
19
|
+
@wombat_yml = opts.wombat_yml
|
20
|
+
@nosuffix = opts.nosuffix.nil? ? false : true
|
21
|
+
end
|
22
|
+
|
23
|
+
def start
|
24
|
+
update_lock(cloud) if lock_opt
|
25
|
+
update_template(cloud) if template_opt
|
26
|
+
create_stack(stack)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def create_stack(stack)
|
32
|
+
|
33
|
+
# determine the filename of the stack
|
34
|
+
filename = stack
|
35
|
+
|
36
|
+
# work out the name of the stack to be created
|
37
|
+
if !@stack_name.nil?
|
38
|
+
|
39
|
+
# As the stack name has been specified then set nosuffix
|
40
|
+
@nosuffix = true
|
41
|
+
stack = stack_name
|
42
|
+
end
|
43
|
+
|
44
|
+
# Deploy the template to the correct stack
|
45
|
+
case @cloud
|
46
|
+
when "aws"
|
47
|
+
|
48
|
+
template_file = File.read("#{conf['stack_dir']}/#{filename}.json")
|
49
|
+
cfn = ::Aws::CloudFormation::Client.new(region: lock['aws']['region'])
|
50
|
+
|
51
|
+
banner("Creating CloudFormation stack")
|
52
|
+
resp = cfn.create_stack({
|
53
|
+
stack_name: "#{stack}",
|
54
|
+
template_body: template_file,
|
55
|
+
capabilities: ["CAPABILITY_IAM"],
|
56
|
+
on_failure: "DELETE",
|
57
|
+
parameters: [
|
58
|
+
{
|
59
|
+
parameter_key: "KeyName",
|
60
|
+
parameter_value: lock['aws']['keypair'],
|
61
|
+
}
|
62
|
+
]
|
63
|
+
})
|
64
|
+
puts "Created: #{resp.stack_id}"
|
65
|
+
when "azure"
|
66
|
+
|
67
|
+
banner("Creating Azure RM stack")
|
68
|
+
|
69
|
+
# determine the path to the arm template
|
70
|
+
template_file = File.read("#{conf['stack_dir']}/#{filename}.json")
|
71
|
+
|
72
|
+
# determine the name of the deployment
|
73
|
+
deployment_name = format('deploy-%s', Time.now().to_i)
|
74
|
+
|
75
|
+
# determine the name of the resource group
|
76
|
+
resource_group_name = stack
|
77
|
+
if !nosuffix
|
78
|
+
resource_group_name = format('%s-%s', resource_group_name, Time.now.strftime('%Y%m%d%H%M%S'))
|
79
|
+
end
|
80
|
+
|
81
|
+
# Connect to azure
|
82
|
+
azure_conn = connect_azure()
|
83
|
+
|
84
|
+
# Create a resource client so that the template can be deployed
|
85
|
+
@resource_management_client = Azure::ARM::Resources::ResourceManagementClient.new(azure_conn)
|
86
|
+
@resource_management_client.subscription_id = ENV['AZURE_SUBSCRIPTION_ID']
|
87
|
+
|
88
|
+
# Create the resource group for the deployment
|
89
|
+
create_resource_group(resource_management_client,
|
90
|
+
resource_group_name,
|
91
|
+
wombat['azure']['location'],
|
92
|
+
wombat['owner'],
|
93
|
+
wombat['azure']['tags'])
|
94
|
+
|
95
|
+
# Create the deployment definition
|
96
|
+
deployment = Azure::ARM::Resources::Models::Deployment.new
|
97
|
+
deployment.properties = Azure::ARM::Resources::Models::DeploymentProperties.new
|
98
|
+
deployment.properties.mode = Azure::ARM::Resources::Models::DeploymentMode::Incremental
|
99
|
+
deployment.properties.template = JSON.parse(template_file)
|
100
|
+
|
101
|
+
# Perform the deployment to the named resource group
|
102
|
+
begin
|
103
|
+
resource_management_client.deployments.begin_create_or_update_async(resource_group_name, deployment_name, deployment).value!
|
104
|
+
rescue MsRestAzure::AzureOperationError => operation_error
|
105
|
+
rest_error = operation_error.body['error']
|
106
|
+
deployment_active = rest_error['code'] == 'DeploymentActive'
|
107
|
+
if deployment_active
|
108
|
+
info format("Deployment for resource group '%s' is ongoing", resource_group_name)
|
109
|
+
else
|
110
|
+
warn rest_error
|
111
|
+
raise operation_error
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# Monitor the deployment
|
116
|
+
if @azure_async
|
117
|
+
info "Deployment operation accepted. Use the Azure Portal to check progress"
|
118
|
+
else
|
119
|
+
follow_azure_deployment(resource_group_name, deployment_name)
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
end
|
128
|
+
end
|
data/lib/wombat/init.rb
CHANGED
@@ -1,32 +1,32 @@
|
|
1
|
-
require 'wombat/common'
|
2
|
-
|
3
|
-
module Wombat
|
4
|
-
class InitRunner
|
5
|
-
include Wombat::Common
|
6
|
-
|
7
|
-
attr_reader :path
|
8
|
-
|
9
|
-
def initialize(opts)
|
10
|
-
@path = opts.path.nil? ? Dir.pwd : opts.path
|
11
|
-
end
|
12
|
-
|
13
|
-
def start
|
14
|
-
copy_files(path)
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def copy_files(path)
|
20
|
-
p = path == Dir.pwd ? '.' : path
|
21
|
-
gen_dir = "#{File.expand_path("../..", File.dirname(__FILE__))}/generator_files"
|
22
|
-
Dir["#{gen_dir}/*"].each do |source|
|
23
|
-
if !File.exist?("#{p}/#{File.basename(source)}")
|
24
|
-
banner("create: #{p}/#{File.basename(source)}")
|
25
|
-
FileUtils.cp_r source, path
|
26
|
-
else
|
27
|
-
warn("#{p}/#{File.basename(source)} already exists")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
1
|
+
require 'wombat/common'
|
2
|
+
|
3
|
+
module Wombat
|
4
|
+
class InitRunner
|
5
|
+
include Wombat::Common
|
6
|
+
|
7
|
+
attr_reader :path
|
8
|
+
|
9
|
+
def initialize(opts)
|
10
|
+
@path = opts.path.nil? ? Dir.pwd : opts.path
|
11
|
+
end
|
12
|
+
|
13
|
+
def start
|
14
|
+
copy_files(path)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def copy_files(path)
|
20
|
+
p = path == Dir.pwd ? '.' : path
|
21
|
+
gen_dir = "#{File.expand_path("../..", File.dirname(__FILE__))}/generator_files"
|
22
|
+
Dir["#{gen_dir}/*"].each do |source|
|
23
|
+
if !File.exist?("#{p}/#{File.basename(source)}")
|
24
|
+
banner("create: #{p}/#{File.basename(source)}")
|
25
|
+
FileUtils.cp_r source, path
|
26
|
+
else
|
27
|
+
warn("#{p}/#{File.basename(source)} already exists")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/wombat/latest.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
|
-
require "wombat/common"
|
2
|
-
require "wombat/aws"
|
3
|
-
|
4
|
-
# http://docs.aws.amazon.com/sdkforruby/api/Aws/EC2/Client.html#describe_images-instance_method
|
5
|
-
# https://github.com/test-kitchen/kitchen-ec2/blob/aa8e7f2cf9bfbb10fa4057f3297c2a20dc079f7b/lib/kitchen/driver/aws/standard_platform.rb
|
6
|
-
# https://github.com/test-kitchen/kitchen-ec2/blob/aa8e7f2cf9bfbb10fa4057f3297c2a20dc079f7b/lib/kitchen/driver/aws/standard_platform/ubuntu.rb
|
7
|
-
|
8
|
-
module Wombat
|
9
|
-
class LatestRunner
|
10
|
-
include Wombat::Common
|
11
|
-
include Wombat::Aws
|
12
|
-
|
13
|
-
attr_reader :stack, :cloud, :lock_opt, :template_opt
|
14
|
-
|
15
|
-
def initialize(opts)
|
16
|
-
@cloud = opts.cloud.nil? ? "aws" : opts.cloud
|
17
|
-
end
|
18
|
-
|
19
|
-
def start
|
20
|
-
if cloud =~ /aws/
|
21
|
-
find_latest_amis
|
22
|
-
else
|
23
|
-
puts "Unsupported for #{cloud}"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
1
|
+
require "wombat/common"
|
2
|
+
require "wombat/aws"
|
3
|
+
|
4
|
+
# http://docs.aws.amazon.com/sdkforruby/api/Aws/EC2/Client.html#describe_images-instance_method
|
5
|
+
# https://github.com/test-kitchen/kitchen-ec2/blob/aa8e7f2cf9bfbb10fa4057f3297c2a20dc079f7b/lib/kitchen/driver/aws/standard_platform.rb
|
6
|
+
# https://github.com/test-kitchen/kitchen-ec2/blob/aa8e7f2cf9bfbb10fa4057f3297c2a20dc079f7b/lib/kitchen/driver/aws/standard_platform/ubuntu.rb
|
7
|
+
|
8
|
+
module Wombat
|
9
|
+
class LatestRunner
|
10
|
+
include Wombat::Common
|
11
|
+
include Wombat::Aws
|
12
|
+
|
13
|
+
attr_reader :stack, :cloud, :lock_opt, :template_opt
|
14
|
+
|
15
|
+
def initialize(opts)
|
16
|
+
@cloud = opts.cloud.nil? ? "aws" : opts.cloud
|
17
|
+
end
|
18
|
+
|
19
|
+
def start
|
20
|
+
if cloud =~ /aws/
|
21
|
+
find_latest_amis
|
22
|
+
else
|
23
|
+
puts "Unsupported for #{cloud}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|