sambot 0.1.115 → 0.1.117
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sambot/chef/cookbook.rb +39 -74
- data/lib/sambot/chef/generator.rb +53 -0
- data/lib/sambot/chef/hooks.rb +17 -0
- data/lib/sambot/chef/kitchen.rb +49 -36
- data/lib/sambot/chef/metadata.rb +27 -25
- data/lib/sambot/cli.rb +7 -3
- data/lib/sambot/commands/base_command.rb +13 -3
- data/lib/sambot/commands/cookbook_cmd.rb +45 -0
- data/lib/sambot/commands/session_cmd.rb +26 -0
- data/lib/sambot/commands/{workstation.rb → workstation_cmd.rb} +5 -2
- data/lib/sambot/dns/records.rb +1 -1
- data/lib/sambot/template.rb +27 -0
- data/lib/sambot/templates/.config.yml.erb +16 -0
- data/lib/sambot/templates/{.gitignore → .gitignore.sample} +0 -0
- data/lib/sambot/templates/.kitchen.yml.erb +10 -1
- data/lib/sambot/templates/Vagrantfile.erb +143 -0
- data/lib/sambot/templates/bootstrap.ps1 +33 -0
- data/lib/sambot/templates/bootstrap.sh +24 -0
- data/lib/sambot/templates/metadata.rb.erb +1 -0
- data/lib/sambot/ui.rb +8 -0
- data/lib/sambot/version.rb +1 -1
- data/lib/sambot/{developer_workflow → workflow}/brew.rb +1 -1
- data/lib/sambot/{developer_workflow → workflow}/dns.rb +1 -1
- data/lib/sambot/{developer_workflow → workflow}/networking.rb +1 -1
- data/lib/sambot/{developer_workflow → workflow}/proxy.rb +1 -1
- data/lib/sambot/{developer_workflow → workflow}/session.rb +1 -1
- data/lib/sambot/{developer_workflow → workflow}/tunnel.rb +1 -1
- data/lib/sambot/{developer_workflow → workflow}/tunnels.rb +1 -1
- data/lib/sambot/{developer_workflow → workflow}/vault.rb +1 -1
- data/lib/sambot/{developer_workflow → workflow}/workstation.rb +1 -1
- data/lib/sambot.rb +12 -21
- metadata +22 -28
- data/lib/sambot/commands/cookbook.rb +0 -47
- data/lib/sambot/commands/session.rb +0 -28
- data/lib/sambot/docs/dns/add.txt +0 -0
- data/lib/sambot/docs/dns/list.txt +0 -0
- data/lib/sambot/docs/dns/remove.txt +0 -0
- data/lib/sambot/docs/dns/show.txt +0 -0
- data/lib/sambot/docs/instance/generate.txt +0 -0
- data/lib/sambot/docs/report/consistency.txt +0 -18
- data/lib/sambot/docs/team/list.txt +0 -0
- data/lib/sambot/file_management/file_checker.rb +0 -43
- data/lib/sambot/file_management/template_provider.rb +0 -13
- data/lib/sambot/reports/consistency_report.rb +0 -0
- data/lib/sambot/ssh/config_file.rb +0 -75
- data/lib/sambot/ssh/config_section.rb +0 -84
- data/lib/sambot/ssh/parser.rb +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5410b3c608857a6491424bf29399106cf7023930
|
4
|
+
data.tar.gz: 529645ac3268d9f87102f4e0311f1368d368d4c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1903dee501f46a5658f80a318e957ef75919d1799e65874b1fa99037c106825a4def5f509c38afcefaca9e03669dddb9b088ba29bb78747a2531c4d13f17a7b2
|
7
|
+
data.tar.gz: f1960f6ebcb4b8b699f344da6314cb6ba10446d3357f80f1bb2b2e41f224124a440d82461996b0cba451934b7f744715f81a7836057b508f28840ddbfc65277d
|
data/lib/sambot/chef/cookbook.rb
CHANGED
@@ -7,100 +7,65 @@ module Sambot
|
|
7
7
|
module Chef
|
8
8
|
class Cookbook
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
ESSENTIAL_FILES = [
|
11
|
+
'.config.yml',
|
12
|
+
'recipes',
|
13
|
+
'README.md'
|
14
|
+
].freeze
|
15
|
+
|
16
|
+
GENERATED_FILES = {
|
17
|
+
'teamcity.sh.erb': {eruby: true, dest: 'teamcity.sh', platform: [:windows, :centos]},
|
18
|
+
'chefignore': {eruby: false, dest: 'chefignore', platform: [:windows, :centos]},
|
19
|
+
'Berksfile': {eruby: false, dest: 'Berksfile', platform: [:windows, :centos]},
|
20
|
+
'.rubocop.yml': {eruby: false, dest: '.rubocop.yml', platform: [:windows, :centos]},
|
21
|
+
'.gitignore.sample': {eruby: false, dest: '.gitignore', platform: [:windows, :centos]},
|
22
|
+
'bootstrap.sh': {eruby: false, dest: 'bootstrap.sh', platform: [:centos]},
|
23
|
+
'bootstrap.ps1': {eruby: false, dest: 'bootstrap.ps1', platform: [:windows]},
|
24
|
+
'Vagrantfile.erb': {eruby: false, dest: 'Vagrantfile.erb', platform: [:windows, :centos]},
|
25
|
+
'winrm_config': {eruby: false, dest: 'winrm_config', platform: [:windows]}
|
26
|
+
}
|
27
|
+
|
28
|
+
CHEF_ARTEFACTS = ['Berksfile.lock']
|
29
|
+
|
30
|
+
KITCHEN_FILES_PATTERN = '\.kitchen*\.yml'
|
31
|
+
|
32
|
+
class << self
|
15
33
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
34
|
+
def build(config)
|
35
|
+
Generator.from_templates(config['platforms'], ESSENTIAL_FILES, GENERATED_FILES)
|
36
|
+
Kitchen.setup(config)
|
37
|
+
Metadata.generate(config)
|
38
|
+
Hooks.copy()
|
21
39
|
UI.info('The cookbook has been successfully built.')
|
22
40
|
end
|
23
41
|
|
24
|
-
def
|
42
|
+
def clean()
|
25
43
|
UI.info('Removing all generated files from this cookbook.')
|
26
|
-
targets = ['metadata.rb', '
|
27
|
-
targets.each
|
28
|
-
delete_file(file)
|
29
|
-
end
|
44
|
+
targets = ['metadata.rb', 'Berksfile.lock'] + GENERATED_FILES.map{ |key, val| val[:dest]} + Dir.glob(KITCHEN_FILES_PATTERN) - ['.gitignore']
|
45
|
+
targets.each { |file| delete(file) }
|
30
46
|
UI.info('The cookbook has been successfully cleaned.')
|
31
47
|
end
|
32
48
|
|
33
|
-
def
|
34
|
-
Git.init(name)
|
35
|
-
Dir.chdir(name) do
|
36
|
-
['test', 'spec', 'recipes'].each {|target|
|
49
|
+
def generate(config)
|
50
|
+
Git.init(config[:name])
|
51
|
+
Dir.chdir(config[:name]) do
|
52
|
+
['test', 'spec', 'recipes'].each {|target| FileUtils.mkdir(target) }
|
37
53
|
FileUtils.touch('README.md')
|
38
|
-
|
39
|
-
|
54
|
+
Template.new('.config.yml.erb').write(config, '.config.yml')
|
55
|
+
UI.debug("./.config.yml has been added to the cookbook.")
|
40
56
|
end
|
41
57
|
UI.info('The cookbook has been successfully generated.')
|
42
58
|
end
|
43
59
|
|
44
60
|
private
|
45
61
|
|
46
|
-
def
|
47
|
-
contents = {
|
48
|
-
'name' => name,
|
49
|
-
'version' => '0.0.1',
|
50
|
-
'platforms' => platforms,
|
51
|
-
'identifier' => '',
|
52
|
-
'suites' => [{
|
53
|
-
'name' => 'default',
|
54
|
-
'run_list' => [
|
55
|
-
"recipe[#{name}]"
|
56
|
-
],
|
57
|
-
'verifier' => {
|
58
|
-
'inspec_tests' => ['./test']
|
59
|
-
}
|
60
|
-
}],
|
61
|
-
'description' => description,
|
62
|
-
}.to_yaml
|
63
|
-
File.write('.config.yml', contents)
|
64
|
-
UI.debug("./.config.yml has been added to the cookbook.")
|
65
|
-
end
|
66
|
-
|
67
|
-
def self.copy_git_hooks
|
68
|
-
working_path = '.git/hooks/pre-push'
|
69
|
-
template_path = FileManagement::TemplateProvider.get_path('pre-push')
|
70
|
-
File.delete(working_path) if File.exist?(working_path)
|
71
|
-
FileUtils.cp(template_path, working_path)
|
72
|
-
UI.debug("The pre-push Git hook has been added to the cookbook.")
|
73
|
-
end
|
74
|
-
|
75
|
-
def self.delete_file(filename)
|
76
|
-
filename = filename.gsub(/\.erb/, '') if filename.end_with?(".erb")
|
62
|
+
def delete(filename)
|
77
63
|
return unless File.exist?(filename)
|
78
64
|
File.delete(filename)
|
79
65
|
UI.debug("./#{filename} has been removed.")
|
80
66
|
end
|
81
67
|
|
82
|
-
def self.validate_cookbook_structure(platform, essential_files, generated_files)
|
83
|
-
essential_files.each { |path| FileManagement::FileChecker.new.verify(path) }
|
84
|
-
if platform.include?('windows')
|
85
|
-
FileManagement::FileChecker.new.update(['winrm_config'])
|
86
|
-
end
|
87
|
-
FileManagement::FileChecker.new.update(generated_files)
|
88
|
-
end
|
89
|
-
|
90
|
-
def self.setup_test_kitchen(config)
|
91
|
-
files = Chef::Kitchen.generate_yml(config['name'], config['platforms'], config['suites'])
|
92
|
-
files.each do |filename, contents|
|
93
|
-
File.write(filename.to_s, contents)
|
94
|
-
UI.debug("#{filename.to_s} has been added to the cookbook.")
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def self.build_metadata(config)
|
99
|
-
result = Chef::Metadata.generate(config['name'], config['platforms'], config['version'], config['description'], config['dependencies'], config['gems'])
|
100
|
-
File.write('metadata.rb', result)
|
101
|
-
UI.debug("A new metadata.rb file has been generated.")
|
102
|
-
end
|
103
|
-
|
104
68
|
end
|
69
|
+
end
|
105
70
|
end
|
106
71
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sambot
|
4
|
+
module Chef
|
5
|
+
class Generator
|
6
|
+
|
7
|
+
def self.from_templates(platforms, cookbook_essentials, cookbook_generated_files)
|
8
|
+
cookbook_essentials.each { |path| exists!(path) } if cookbook_essentials
|
9
|
+
cookbook_generated_files.each do |template_name, opts|
|
10
|
+
generate_from_template(template_name.to_s, opts, platforms)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def self.exists!(path)
|
17
|
+
return if File.exist?(path) || Dir.exist?(path)
|
18
|
+
raise ApplicationError, "The file or directory #{path} was not found in the current directory."
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.generate_from_template(template_file, opts, platforms)
|
22
|
+
UI.debug("Processing #{template_file} with opts #{opts.inspect} on platform #{platforms}")
|
23
|
+
template = Template.new(template_file)
|
24
|
+
if valid_platform?(opts, platforms)
|
25
|
+
File.delete(opts[:dest]) if File.exist?(opts[:dest])
|
26
|
+
if opts[:eruby]
|
27
|
+
UI.debug("Parsing #{template.path} using Erubis")
|
28
|
+
template.write({}, opts[:dest])
|
29
|
+
else
|
30
|
+
FileUtils.cp(template.path, opts[:dest].to_s)
|
31
|
+
end
|
32
|
+
if File.executable?(template.path)
|
33
|
+
UI.debug("Making #{opts[:dest]} executable")
|
34
|
+
make_executable(template.path, opts[:dest])
|
35
|
+
end
|
36
|
+
UI.debug("#{opts[:dest]} has been added to the cookbook.")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.valid_platform?(opts, platforms)
|
41
|
+
targets = opts[:platform].map { |x| x.to_s}
|
42
|
+
result = targets & platforms
|
43
|
+
result.size > 0
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.make_executable(file, working_path)
|
47
|
+
current_mask = File.stat(file).mode
|
48
|
+
new_mask = current_mask | '0000000000000001'.to_i(2)
|
49
|
+
File.chmod(new_mask, working_path)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sambot
|
4
|
+
module Chef
|
5
|
+
class Hooks
|
6
|
+
|
7
|
+
def self.copy
|
8
|
+
working_path = '.git/hooks/pre-push'
|
9
|
+
template_path = Template.new('pre-push').path
|
10
|
+
File.delete(working_path) if File.exist?(working_path)
|
11
|
+
FileUtils.cp(template_path, working_path)
|
12
|
+
UI.debug("The pre-push Git hook has been added to the cookbook.")
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/sambot/chef/kitchen.rb
CHANGED
@@ -4,49 +4,62 @@ module Sambot
|
|
4
4
|
module Chef
|
5
5
|
class Kitchen
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
7
|
+
LOCAL = '.kitchen.yml'
|
8
|
+
GCP = '.kitchen.gcp.yml'
|
9
|
+
RACKSPACE = '.kitchen.rackspace.yml'
|
10
|
+
|
11
|
+
class << self
|
12
|
+
|
13
|
+
def setup(config)
|
14
|
+
files = generate_yml(config['name'], config['platforms'], config['suites'])
|
15
|
+
files.each do |filename, contents|
|
16
|
+
File.write(filename.to_s, contents)
|
17
|
+
UI.debug("#{filename.to_s} has been added to the cookbook.")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate_yml(cookbook_name, platforms, suites = nil)
|
22
|
+
raise ApplicationError, 'Missing platforms when trying to generate Test-Kitchen YAML.' unless platforms
|
23
|
+
raise ApplicationError, 'Missing cookbook name when trying to generate Test-Kitchen YAML.' unless cookbook_name
|
24
|
+
test_kitchen_configs = {
|
25
|
+
"#{LOCAL}": read_template(LOCAL, cookbook_name, platforms),
|
26
|
+
"#{GCP}": read_template(GCP, cookbook_name, platforms),
|
27
|
+
"#{RACKSPACE}": read_template(RACKSPACE, cookbook_name, platforms)
|
28
|
+
}
|
29
|
+
test_kitchen_configs.each do |key, value|
|
30
|
+
if suites
|
31
|
+
value['suites'] = Marshal.load(Marshal.dump(suites))
|
32
|
+
case key.to_s
|
33
|
+
when LOCAL
|
34
|
+
add_platform_identifier(value, 'LOCAL')
|
35
|
+
when GCP
|
36
|
+
add_platform_identifier(value, 'GCP')
|
37
|
+
when RACKSPACE
|
38
|
+
add_platform_identifier(value, 'RACKSPACE')
|
32
39
|
end
|
33
40
|
end
|
41
|
+
test_kitchen_configs[key] = value.to_yaml
|
34
42
|
end
|
35
|
-
test_kitchen_configs
|
43
|
+
test_kitchen_configs
|
36
44
|
end
|
37
|
-
test_kitchen_configs
|
38
|
-
end
|
39
45
|
|
40
|
-
|
46
|
+
private
|
41
47
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
def add_platform_identifier(value, platform)
|
49
|
+
value['suites'].each do |config|
|
50
|
+
config['attributes'] = config['attributes'] || {}
|
51
|
+
config['attributes']['cloud_platform'] = platform
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def read_template(template, cookbook_name, platforms)
|
56
|
+
result = Template.new("#{template}.erb").evaluate({platforms: platforms}) do |contents|
|
57
|
+
contents.gsub(/@@cookbook_name@@/, cookbook_name)
|
58
|
+
end
|
59
|
+
YAML.load(result.gsub(/\_@/, '<%=').gsub(/@\_/, '%>'))
|
60
|
+
end
|
49
61
|
|
50
62
|
end
|
63
|
+
end
|
51
64
|
end
|
52
65
|
end
|
data/lib/sambot/chef/metadata.rb
CHANGED
@@ -3,37 +3,39 @@
|
|
3
3
|
require 'erubis'
|
4
4
|
|
5
5
|
module Sambot
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
'
|
19
|
-
|
20
|
-
'cookbook_version' => version,
|
21
|
-
'cookbook_description' => description,
|
22
|
-
'cookbook_dependencies' => dependencies,
|
23
|
-
'cookbook_gems' => gems,
|
24
|
-
}
|
25
|
-
generate_metadata(context)
|
6
|
+
module Chef
|
7
|
+
class Metadata
|
8
|
+
|
9
|
+
class << self
|
10
|
+
|
11
|
+
def generate(config, dest = 'metadata.rb')
|
12
|
+
write({
|
13
|
+
'cookbook_name' => config['name'],
|
14
|
+
'cookbook_platforms' => config['platforms'],
|
15
|
+
'cookbook_version' => config['version'],
|
16
|
+
'cookbook_description' => config['description'],
|
17
|
+
'cookbook_dependencies' => map_dependencies(config),
|
18
|
+
'cookbook_gems' => config['gems'] || [],
|
19
|
+
}, dest)
|
26
20
|
end
|
27
21
|
|
28
22
|
private
|
29
23
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
24
|
+
def map_dependencies(config)
|
25
|
+
config['dependencies'] ? config['dependencies'].map { |x| transform_hashes(x) } : []
|
26
|
+
end
|
27
|
+
|
28
|
+
def transform_hashes(obj)
|
29
|
+
obj.is_a?(Hash) ? "#{obj.keys.first}', '#{obj.values.first}" : obj
|
30
|
+
end
|
31
|
+
|
32
|
+
def write(ctx, dest)
|
33
|
+
template = Sambot::Template.new('metadata.rb.erb').write(ctx, dest)
|
34
|
+
UI.debug("A new metadata.rb file has been generated.")
|
35
35
|
end
|
36
36
|
|
37
37
|
end
|
38
|
+
|
39
|
+
end
|
38
40
|
end
|
39
41
|
end
|
data/lib/sambot/cli.rb
CHANGED
@@ -1,16 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'commands/cookbook_cmd'
|
4
|
+
require_relative 'commands/session_cmd'
|
5
|
+
require_relative 'commands/workstation_cmd'
|
6
|
+
|
3
7
|
module Sambot
|
4
8
|
class CLI < Thor
|
5
9
|
|
6
10
|
desc 'cookbook', 'Manage Chef cookbooks'
|
7
|
-
subcommand 'cookbook', Sambot::Commands::
|
11
|
+
subcommand 'cookbook', Sambot::Commands::CookbookCmd
|
8
12
|
|
9
13
|
desc 'session', 'Manage sessions'
|
10
|
-
subcommand 'session', Sambot::Commands::
|
14
|
+
subcommand 'session', Sambot::Commands::SessionCmd
|
11
15
|
|
12
16
|
desc 'workstation', 'Manage engineer workstations'
|
13
|
-
subcommand 'workstation', Sambot::Commands::
|
17
|
+
subcommand 'workstation', Sambot::Commands::WorkstationCmd
|
14
18
|
|
15
19
|
end
|
16
20
|
end
|
@@ -60,15 +60,25 @@ module Sambot
|
|
60
60
|
|
61
61
|
no_commands do
|
62
62
|
|
63
|
+
def missing_credentials(need_dev_credentials, need_sudo_password)
|
64
|
+
return true if need_dev_credentials && (!ENV['SAMBOT_DEV_USERNAME'] && !ENV['SAMBOT_DEV_PASSWORD'])
|
65
|
+
return need_sudo_password && !ENV['SAMBOT_SUDO_PASSWORD']
|
66
|
+
end
|
67
|
+
|
63
68
|
def execute(need_dev_credentials: false, need_sudo_password: false)
|
69
|
+
if missing_credentials(need_dev_credentials, need_sudo_password)
|
70
|
+
UI.info("Sambot will need to make some secure operations on your behalf. You can provide your credentials below or set them as environment variables:")
|
71
|
+
end
|
64
72
|
if need_dev_credentials && !ENV['SAMBOT_DEV_USERNAME']
|
65
|
-
|
73
|
+
ENV['SAMBOT_DEV_USERNAME'] = UI.ask("Please provide your DEV/QE AD username: ")
|
66
74
|
end
|
67
75
|
if need_dev_credentials && !ENV['SAMBOT_DEV_PASSWORD']
|
68
|
-
|
76
|
+
ENV['SAMBOT_DEV_USERNAME'] = UI.ask_password("Please provide your DEV/QE AD password: ")
|
77
|
+
puts "\n"
|
69
78
|
end
|
70
79
|
if need_sudo_password && !ENV['SAMBOT_SUDO_PASSWORD']
|
71
|
-
|
80
|
+
ENV['SAMBOT_DEV_USERNAME'] = UI.ask_password("Please provide your sudo password - this is required for operations such as setting up your local SSH tunnels: ")
|
81
|
+
puts "\n"
|
72
82
|
end
|
73
83
|
Runtime.ensure_latest
|
74
84
|
yield
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'base_command'
|
4
|
+
require_relative '../chef/cookbook'
|
5
|
+
|
6
|
+
module Sambot
|
7
|
+
module Commands
|
8
|
+
|
9
|
+
class CookbookCmd < BaseCommand
|
10
|
+
|
11
|
+
namespace 'cookbook'
|
12
|
+
|
13
|
+
desc 'clean', 'Remove all generated build files from a cookbook'
|
14
|
+
def clean
|
15
|
+
execute { Chef::Cookbook.clean() }
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'build', 'Builds a cookbook from its configuration file'
|
19
|
+
def build
|
20
|
+
execute { Chef::Cookbook.build(config) }
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'generate', 'Creates a new cookbook'
|
24
|
+
def generate
|
25
|
+
execute do
|
26
|
+
config = {
|
27
|
+
name: ask(' What is the name of this cookbook?'),
|
28
|
+
type: ask(' What type of cookbook will this be?', :limited_to => ['wrapper', 'role']),
|
29
|
+
platforms: ask(' What operating system will this cookbook run on?', :limited_to => ['windows', 'centos', 'both']),
|
30
|
+
description: ask(' What does this cookbook do?')
|
31
|
+
}
|
32
|
+
config[:identifier] = ask(' What will be the unique machiner identifier for this role cookbook?') if config[:type] == 'role'
|
33
|
+
config[:platforms] = config[:platforms] == 'both' ? ['centos', 'windows'] : [config[:platforms]]
|
34
|
+
Chef::Cookbook.generate(config)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
desc 'version', 'Gives the cookbook version as a TeamCity service message'
|
39
|
+
def version
|
40
|
+
execute { puts "##teamcity[buildNumber '#{config['version'].to_s}']" }
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'base_command'
|
4
|
+
require_relative '../workflow/session'
|
5
|
+
|
6
|
+
module Sambot
|
7
|
+
module Commands
|
8
|
+
class SessionCmd < BaseCommand
|
9
|
+
|
10
|
+
namespace 'session'
|
11
|
+
|
12
|
+
desc 'start', 'Start a new Sambot session'
|
13
|
+
def start
|
14
|
+
execute(need_dev_credentials: true, need_sudo_password: true) do
|
15
|
+
Workflow::Session.new.start(ENV['SAMBOT_DEV_USERNAME'], ENV['SAMBOT_DEV_PASSWORD'], ENV['SAMBOT_SUDO_PASSWORD'])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'stop', 'Stop any active Sambot session'
|
20
|
+
def stop
|
21
|
+
execute(need_sudo_password: true) { Workflow::Session.new.stop }
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,15 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'base_command'
|
4
|
+
require_relative '../workflow/workstation'
|
5
|
+
|
3
6
|
module Sambot
|
4
7
|
module Commands
|
5
|
-
class
|
8
|
+
class WorkstationCmd < BaseCommand
|
6
9
|
|
7
10
|
namespace 'workstation'
|
8
11
|
|
9
12
|
desc 'configure', 'Sets up an engineering workstation'
|
10
13
|
def configure
|
11
14
|
execute(need_dev_credentials: true, need_sudo_password: true) do
|
12
|
-
|
15
|
+
Workflow::Workstation.configure(ENV['SAMBOT_DEV_PASSWORD'])
|
13
16
|
end
|
14
17
|
end
|
15
18
|
|
data/lib/sambot/dns/records.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sambot
|
4
|
+
class Template
|
5
|
+
|
6
|
+
def initialize(filename)
|
7
|
+
@filename = filename
|
8
|
+
end
|
9
|
+
|
10
|
+
def path
|
11
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'templates', @filename))
|
12
|
+
end
|
13
|
+
|
14
|
+
def evaluate(context = {})
|
15
|
+
input = File.read(path)
|
16
|
+
input = yield(input) if block_given?
|
17
|
+
eruby = Erubis::Eruby.new(input)
|
18
|
+
eruby.evaluate(context)
|
19
|
+
end
|
20
|
+
|
21
|
+
def write(ctx, dest)
|
22
|
+
contents = evaluate(ctx)
|
23
|
+
File.write(dest, contents)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
name: <%= @name %>
|
2
|
+
version: 0.0.1
|
3
|
+
platforms:
|
4
|
+
<% @platforms.each do |platform| %>
|
5
|
+
- <%= platform %>
|
6
|
+
<% end %>
|
7
|
+
identifier: <%= @identifier %>
|
8
|
+
description: <%= @description %>
|
9
|
+
suites:
|
10
|
+
- name: default
|
11
|
+
run_list:
|
12
|
+
- recipe[<%= @name %>::default]
|
13
|
+
verifier:
|
14
|
+
inspec_tests:
|
15
|
+
- name: <%= @name %>-profile
|
16
|
+
git: git@github.exacttarget.com:ads-chef-profiles/<%= @name %>-profile.git
|
File without changes
|
@@ -1,6 +1,10 @@
|
|
1
1
|
---
|
2
2
|
driver:
|
3
3
|
name: "vagrant"
|
4
|
+
synced_folders:
|
5
|
+
- [".", "/vagrant"]
|
6
|
+
provision: true
|
7
|
+
vagrantfile_erb: Vagrantfile.erb
|
4
8
|
|
5
9
|
provisioner:
|
6
10
|
name: chef_zero
|
@@ -12,11 +16,16 @@ provisioner:
|
|
12
16
|
platforms:
|
13
17
|
<% if @platforms.include?('centos') %>
|
14
18
|
- name: "centos-7.2"
|
19
|
+
driver:
|
20
|
+
network:
|
21
|
+
- ["private_network", {ip: "192.168.255.10"}]
|
15
22
|
<% end %>
|
16
23
|
<% if @platforms.include?('windows') %>
|
17
24
|
- name: windows-2012R2
|
18
|
-
|
25
|
+
driver:
|
19
26
|
box: salesforce/Server2012R2
|
27
|
+
network:
|
28
|
+
- ["private_network", {ip: "192.168.255.11"}]
|
20
29
|
transport:
|
21
30
|
name: winrm
|
22
31
|
elevated: true
|