awstool 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6965dafb90d27b6f9d45f95ef6327d1cff5fd160
4
+ data.tar.gz: faeeba88e0ee6d4def432439c2fd5503217180bf
5
+ SHA512:
6
+ metadata.gz: 3606a6bb437760442340ccbc3cfcdf7c49f34bcb050ae91ca013f2f061ca65a138ad33e0a225f336780df4a1db99ee81c9d5d44537c3be48a6e5fc707eb4045d
7
+ data.tar.gz: 0a96e5319bcc70a95a2438b7f143af57919260bbbac7378f488af95863bde9870ef19dc30c62868047d3603c29de55b256b3e9821ec75f081e9a23baac91d212
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.swp
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in awstools.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Nick B
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # Awstools
2
+
3
+ Tool for launching and configuring AWS EC2 instances.
4
+
5
+ ## Installation
6
+
7
+ Not properly gemmed up yet. You'll need to clone and set RUBYLIB environment variable to clonepath/awstools/lib. Requires the fog gem and ruby >=1.9.3.
8
+ ```bash
9
+ export RUBYLIB=/home/user/repos/awstools/lib
10
+ sudo apt-get install ruby-dev # For ubuntu/debian
11
+ gem install fog
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ Copy example/awstools.yaml to ~/.awstools.yaml. Fill it out to your liking.
17
+ ```bash
18
+ cd awstools/bin
19
+ ./awstools hostname
20
+ ```
21
+ This will launch and instance and create an A record with route53.
22
+
23
+
24
+ ## Contributing
25
+
26
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nburg/awstools.
27
+
28
+
29
+ ## License
30
+
31
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
32
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/awstools.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'awstool/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "awstool"
8
+ spec.version = Awstool::VERSION
9
+ spec.authors = ["Nick Burgess"]
10
+ spec.email = ["nburgess@uchicago.edu"]
11
+
12
+ spec.summary = %q{Tool for launching and configuring AWS EC2 instances.}
13
+ spec.description = %q{This will launch new instances, set up dns via route53, install puppet, and set facts.}
14
+ spec.homepage = "https://github.com/nburg/awstools"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "bin"
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.13"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "minitest", "~> 5.0"
27
+
28
+ spec.add_runtime_dependency "fog", '~> 1.38.0'
29
+ end
data/bin/awstool ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'awstool'
4
+ require 'pp'
5
+ require 'fog'
6
+
7
+ options = Awstool::Settings.get_options
8
+
9
+ instance = Awstool::Instance.new(options)
10
+ instance.launch
11
+ instance.set_dns
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "awstool"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,17 @@
1
+ key-name: mykey
2
+ image-id: ami-foobar
3
+ subnet-id: subnet-foobar
4
+ security-group-ids:
5
+ - sg-foobar
6
+ - sg-foobaz
7
+ iam-instance-profile: myprofile
8
+ access_key_id: ABRACADABRA
9
+ access_key: somelongstring
10
+ region: us-east-1
11
+ instance-type: t2.medium
12
+ facts:
13
+ foo: bar
14
+ csr_attributes: anotherlongstring
15
+ dns_zone:
16
+ zone-id: FAKEID
17
+ email: admin@example.com
@@ -0,0 +1,43 @@
1
+ require 'erb'
2
+
3
+ class Awstool::Instance
4
+ def initialize(options)
5
+ @options = options
6
+ @compute = Fog::Compute.new(
7
+ :provider => 'AWS',
8
+ :region => @options['region'],
9
+ :aws_access_key_id => @options['access_key_id'],
10
+ :aws_secret_access_key => @options['access_key'],
11
+ )
12
+ end
13
+
14
+ def launch
15
+ @instance = @compute.servers.create(
16
+ image_id: @options['image-id'],
17
+ flavor_id: @options['instance-type'],
18
+ security_group_ids: @options['security-group-ids'],
19
+ subnet_id: @options['subnet-id'],
20
+ key_name: @options['key-name'],
21
+ tags: @options['tags'],
22
+ user_data: ERB.new(File.read(@options['userdata'])).result
23
+ )
24
+ @instance.wait_for { ready? }
25
+ pp @instance.reload
26
+ end
27
+
28
+ def set_dns
29
+ dns = Fog::DNS.new(
30
+ :provider => 'AWS',
31
+ :aws_access_key_id => @options['access_key_id'],
32
+ :aws_secret_access_key => @options['access_key'],
33
+ )
34
+
35
+ zone = dns.zones.get(@options['dns-zone-id'])
36
+
37
+ @record = zone.records.create(
38
+ value: @instance.private_ip_address,
39
+ name: @options['hostname'],
40
+ type: 'A'
41
+ )
42
+ end
43
+ end
@@ -0,0 +1,69 @@
1
+ require 'optparse'
2
+ require 'psych'
3
+
4
+ class Awstool::Settings
5
+ @options = {}
6
+
7
+ attr_reader :options
8
+
9
+ def self.get_options
10
+ set_default
11
+ get_rc
12
+ get_flags
13
+ @options
14
+ end
15
+
16
+ private
17
+
18
+ def self.get_flags
19
+ OptionParser.new do |opts|
20
+ opts.banner = 'Usage: awstool [options] hostname'
21
+
22
+ opts.on('-h', '--help', 'Prints this help') do
23
+ puts opts
24
+ exit
25
+ end
26
+
27
+ opts.on('-f', '--facts FACT1,FACT2', Array, 'Seed new instance with puppet facts') do |facts|
28
+ facts.each do |fact|
29
+ split_fact = fact.split('=')
30
+ @options['facts'][split_fact[0]] = split_fact[1]
31
+ end
32
+ end
33
+
34
+ opts.on('-t', '--tags TAG1,TAG2', Array, 'Set EC2 instance tags') do |tags|
35
+ tags.each do |tag|
36
+ split_tag = tag.split('=')
37
+ @options['tags'][split_tag[0]] = split_tag[1]
38
+ end
39
+ end
40
+
41
+ opts.on('--debug', 'Prints some extra output helpful for debugging') do
42
+ @options['debug'] = true
43
+ end
44
+ end.parse!
45
+
46
+ [ 'hostname' ].each do |v|
47
+ if ARGV.empty?
48
+ puts "#{v} string is required."
49
+ exit 1
50
+ else
51
+ @options[v] = ARGV.shift
52
+ end
53
+ end
54
+ @options['tags']['Name'] = @options['hostname']
55
+ end
56
+
57
+ def self.get_rc
58
+ awsconf = "#{ENV['HOME']}/.awstool.yaml"
59
+ if File.exist?(awsconf)
60
+ @options.merge!(Psych.load_file(awsconf))
61
+ end
62
+ end
63
+
64
+ def self.set_default
65
+ @options['userdata'] = File.expand_path('../userdata/default.erb')
66
+ @options['facts'] = {}
67
+ @options['tags']= {}
68
+ end
69
+ end
@@ -0,0 +1,3 @@
1
+ class Awstool
2
+ VERSION = '0.0.2'
3
+ end
data/lib/awstool.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "awstool/version"
2
+ require 'awstool/settings'
3
+ require 'awstool/instance'
4
+
5
+ class Awstools
6
+ end
@@ -0,0 +1,35 @@
1
+ #cloud-config
2
+
3
+ bootcmd:
4
+ - echo <%= options['hostname'] %> > /etc/hostname
5
+ - hostname -F /etc/hostname
6
+
7
+ hostname: <%= options['hostname'] %>
8
+ fqdn: <%= options['hostname'] %>
9
+ manage_etc_hosts: true
10
+
11
+ package_upgrade: true
12
+ package_reboot_if_required: true
13
+
14
+ write_files:
15
+ <% if options['csr_attributes'] %>
16
+ - content: |
17
+ ---
18
+ custom_attributes:
19
+ 1.2.840.113549.1.9.7: <%= options['csr_attributes'] %>
20
+ path: /etc/puppetlab/puppet/csr_attributes.yaml
21
+ permissions: 0600
22
+ <% end %>
23
+ <% options['facts'].each do |fact, value| %>
24
+ - content: |
25
+ ---
26
+ <%= fact %>: <%= value %>
27
+ path: /opt/puppetlabs/facter/facts.d/<%= fact %>.yaml
28
+ permissions: '0644'
29
+ <% end %>
30
+
31
+ <%# runcmd: %>
32
+ <%# - rpm -ivh https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm %>
33
+ <%# - yum -y install puppet-agent %>
34
+ <%# - puppet agent -t --waitforcert 5 --server henson.uchicago.edu %>
35
+ <%# - puppet agent -t %>
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: awstool
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Nick Burgess
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fog
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.38.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.38.0
69
+ description: This will launch new instances, set up dns via route53, install puppet,
70
+ and set facts.
71
+ email:
72
+ - nburgess@uchicago.edu
73
+ executables:
74
+ - awstool
75
+ - console
76
+ - setup
77
+ extensions: []
78
+ extra_rdoc_files: []
79
+ files:
80
+ - ".gitignore"
81
+ - ".travis.yml"
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - awstools.gemspec
87
+ - bin/awstool
88
+ - bin/console
89
+ - bin/setup
90
+ - examples/awstools.yaml
91
+ - lib/awstool.rb
92
+ - lib/awstool/instance.rb
93
+ - lib/awstool/settings.rb
94
+ - lib/awstool/version.rb
95
+ - userdata/default.erb
96
+ homepage: https://github.com/nburg/awstools
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.5.1
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Tool for launching and configuring AWS EC2 instances.
120
+ test_files: []