awstool 0.0.2 → 0.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6965dafb90d27b6f9d45f95ef6327d1cff5fd160
4
- data.tar.gz: faeeba88e0ee6d4def432439c2fd5503217180bf
3
+ metadata.gz: fa7519114222d1de674841c22bee82fc62444d4e
4
+ data.tar.gz: 57ac99fc9beb9fbb41e576771d3ce9eba096addd
5
5
  SHA512:
6
- metadata.gz: 3606a6bb437760442340ccbc3cfcdf7c49f34bcb050ae91ca013f2f061ca65a138ad33e0a225f336780df4a1db99ee81c9d5d44537c3be48a6e5fc707eb4045d
7
- data.tar.gz: 0a96e5319bcc70a95a2438b7f143af57919260bbbac7378f488af95863bde9870ef19dc30c62868047d3603c29de55b256b3e9821ec75f081e9a23baac91d212
6
+ metadata.gz: 47e913f259f1c39c6ab791e1fa795e49f0c7cbb03c42e03dec5a58b2097d52616b3b3d2681b7448481681805550a1f15a9482561907c20486b79107ce5b41bc7
7
+ data.tar.gz: db8eaa00d531d0b330a32f894f00ec2aca07e74b274c1197e08d233eb274248ee3cae14d47a4e254a3dc5251376907e04af6842080112e3d701372c08e7e0c13
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  *.swp
11
+ /bin/console
data/README.md CHANGED
@@ -1,25 +1,34 @@
1
- # Awstools
1
+ # Awstool
2
2
 
3
3
  Tool for launching and configuring AWS EC2 instances.
4
4
 
5
5
  ## Installation
6
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
7
  ```bash
9
- export RUBYLIB=/home/user/repos/awstools/lib
10
- sudo apt-get install ruby-dev # For ubuntu/debian
11
- gem install fog
8
+ gem install awstool
12
9
  ```
13
10
 
14
11
  ## Usage
15
12
 
16
13
  Copy example/awstools.yaml to ~/.awstools.yaml. Fill it out to your liking.
17
14
  ```bash
18
- cd awstools/bin
19
- ./awstools hostname
15
+ awstool floop.example.com
20
16
  ```
21
- This will launch and instance and create an A record with route53.
22
-
17
+ This will launch and instance and create an A record with route53.
18
+ You can split your settings files up and then merge them on the command line with the -o flag.
19
+ ```bash
20
+ awstool -o ~/ubuntu-14.04.yaml,~/webserver.yaml floop.example.com
21
+ ```
22
+ This will allow for different levels of templating. Particularly useful for setting puppet
23
+ options and security groups. Launch a bunch of instances off of the same configs like so.
24
+ ```bash
25
+ awstool -o ~/ubuntu-14.04.yaml,~/webserver.yaml floop1.example.com floop2.example.com jb.example.com
26
+ # or
27
+ awstool -o ~/ubuntu-14.04.yaml,~/webserver.yaml floop{1..5}.example.com
28
+ ```
29
+ When launching multiple instances the tool will choose a random subnet from the subnet-ids array unless
30
+ the -s flag or the 'subnet-id-index' option is set. It can also balance between the subnets with
31
+ 'subnet_balance: true' in settings.
23
32
 
24
33
  ## Contributing
25
34
 
data/bin/awstool CHANGED
@@ -2,10 +2,17 @@
2
2
 
3
3
  require 'awstool'
4
4
  require 'pp'
5
- require 'fog'
6
5
 
7
6
  options = Awstool::Settings.get_options
7
+ pp options
8
8
 
9
- instance = Awstool::Instance.new(options)
10
- instance.launch
11
- instance.set_dns
9
+ options['hostnames'].each do |hostname|
10
+ if options['subnet_balance']
11
+ options['subnet-id-index'] = ( options['subnet-id-index'] + 1 ) % ( options['subnet-ids'].length - 1 )
12
+ end
13
+ options['tags']['Name'] = hostname
14
+ options['hostname'] = hostname
15
+ instance = Awstool::Instance.new(options)
16
+ instance.launch
17
+ instance.set_dns
18
+ end
@@ -1,6 +1,8 @@
1
1
  key-name: mykey
2
2
  image-id: ami-foobar
3
- subnet-id: subnet-foobar
3
+ subnet-ids:
4
+ - subnet-foobar
5
+ - subnet-foobas
4
6
  security-group-ids:
5
7
  - sg-foobar
6
8
  - sg-foobaz
@@ -11,7 +13,11 @@ region: us-east-1
11
13
  instance-type: t2.medium
12
14
  facts:
13
15
  foo: bar
14
- csr_attributes: anotherlongstring
15
- dns_zone:
16
- zone-id: FAKEID
17
- email: admin@example.com
16
+ puppet_install:
17
+ package_manager: apt-get
18
+ repo_package: puppetlabs-release-pc1-trusty.deb
19
+ csr_attributes: longrandomstring
20
+ server: puppet.example.com
21
+ environment: aws
22
+ purge_dns: true
23
+ subnet_balance: true
@@ -1,13 +1,14 @@
1
1
  require 'erb'
2
+ require 'fog'
2
3
 
3
4
  class Awstool::Instance
4
5
  def initialize(options)
5
6
  @options = options
6
7
  @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'],
8
+ provider: 'AWS',
9
+ region: @options['region'],
10
+ aws_access_key_id: @options['access_key_id'],
11
+ aws_secret_access_key: @options['access_key'],
11
12
  )
12
13
  end
13
14
 
@@ -16,7 +17,7 @@ class Awstool::Instance
16
17
  image_id: @options['image-id'],
17
18
  flavor_id: @options['instance-type'],
18
19
  security_group_ids: @options['security-group-ids'],
19
- subnet_id: @options['subnet-id'],
20
+ subnet_id: @options['subnet-ids'][@options['subnet-id-index']],
20
21
  key_name: @options['key-name'],
21
22
  tags: @options['tags'],
22
23
  user_data: ERB.new(File.read(@options['userdata'])).result
@@ -27,13 +28,20 @@ class Awstool::Instance
27
28
 
28
29
  def set_dns
29
30
  dns = Fog::DNS.new(
30
- :provider => 'AWS',
31
- :aws_access_key_id => @options['access_key_id'],
32
- :aws_secret_access_key => @options['access_key'],
31
+ provider: 'AWS',
32
+ aws_access_key_id: @options['access_key_id'],
33
+ aws_secret_access_key: @options['access_key'],
33
34
  )
34
35
 
35
36
  zone = dns.zones.get(@options['dns-zone-id'])
36
37
 
38
+ if @options['purge_dns']
39
+ record = zone.records.find { |r| r.name == "#{@options['hostname']}." }
40
+ if record
41
+ record.destroy
42
+ end
43
+ end
44
+
37
45
  @record = zone.records.create(
38
46
  value: @instance.private_ip_address,
39
47
  name: @options['hostname'],
@@ -3,6 +3,7 @@ require 'psych'
3
3
 
4
4
  class Awstool::Settings
5
5
  @options = {}
6
+ @option_files = []
6
7
 
7
8
  attr_reader :options
8
9
 
@@ -10,6 +11,9 @@ class Awstool::Settings
10
11
  set_default
11
12
  get_rc
12
13
  get_flags
14
+ @option_files.each do |f|
15
+ @options.merge!(f)
16
+ end
13
17
  @options
14
18
  end
15
19
 
@@ -41,17 +45,29 @@ class Awstool::Settings
41
45
  opts.on('--debug', 'Prints some extra output helpful for debugging') do
42
46
  @options['debug'] = true
43
47
  end
44
- end.parse!
45
48
 
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
49
+ opts.on('-s', '--subnet-id-index INDEX', 'Select a subnet-id from you subnet-ids array.') do |index|
50
+ @options['subnet-id-index'] = index.to_i
51
+ end
52
+
53
+ opts.on(
54
+ '-o',
55
+ '--options-file FILE1,FILE2',
56
+ Array,
57
+ 'List option files that will merge and override settings in .awstool.yaml. Last entry takes precedence.' ) do |of|
58
+ of.each do |f|
59
+ @option_files << Psych.load_file(File.expand_path(f))
60
+ end
52
61
  end
62
+
63
+ end.parse!
64
+
65
+ if ARGV.empty?
66
+ puts "hostname string is required."
67
+ exit 1
68
+ else
69
+ @options['hostnames'] = ARGV
53
70
  end
54
- @options['tags']['Name'] = @options['hostname']
55
71
  end
56
72
 
57
73
  def self.get_rc
@@ -59,11 +75,13 @@ class Awstool::Settings
59
75
  if File.exist?(awsconf)
60
76
  @options.merge!(Psych.load_file(awsconf))
61
77
  end
78
+ @options['subnet-id-index'] = rand(@options['subnet-ids'].length - 1 )
62
79
  end
63
80
 
64
81
  def self.set_default
65
82
  @options['userdata'] = File.expand_path('../userdata/default.erb')
66
83
  @options['facts'] = {}
67
84
  @options['tags']= {}
85
+ @options['hostnames'] = []
68
86
  end
69
87
  end
@@ -1,3 +1,3 @@
1
1
  class Awstool
2
- VERSION = '0.0.2'
2
+ VERSION = '0.1.0'
3
3
  end
data/userdata/default.erb CHANGED
@@ -12,12 +12,12 @@ package_upgrade: true
12
12
  package_reboot_if_required: true
13
13
 
14
14
  write_files:
15
- <% if options['csr_attributes'] %>
15
+ <% if options['puppet_install']['csr_attributes'] %>
16
16
  - content: |
17
17
  ---
18
18
  custom_attributes:
19
- 1.2.840.113549.1.9.7: <%= options['csr_attributes'] %>
20
- path: /etc/puppetlab/puppet/csr_attributes.yaml
19
+ 1.2.840.113549.1.9.7: <%= options['puppet_install']['csr_attributes'] %>
20
+ path: /etc/puppetlabs/puppet/csr_attributes.yaml
21
21
  permissions: 0600
22
22
  <% end %>
23
23
  <% options['facts'].each do |fact, value| %>
@@ -28,8 +28,18 @@ write_files:
28
28
  permissions: '0644'
29
29
  <% end %>
30
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 %>
31
+ <% if options['puppet_install'] %>
32
+ runcmd:
33
+ <% if options['puppet_install']['package_manager'] == 'apt-get' %>
34
+ - wget https://apt.puppetlabs.com/<%= options['puppet_install']['repo_package'] %>
35
+ - dpkg -i /<%= options['puppet_install']['repo_package'] %>
36
+ - apt-get update
37
+ - apt-get -y install puppet-agent
38
+ <% elsif options['puppet_install']['package_manager'] == 'yum' %>
39
+ - rpm -ivh https://yum.puppetlabs.com/<%= options['puppet_install']['repo_package'] %>
40
+ - yum -y install puppet-agent
41
+ <% end %>
42
+ - /opt/puppetlabs/bin/puppet agent -t --waitforcert 5 --server <%= options['puppet_install']['server'] %> <% if options['puppet_install']['environment'] %> --environment <%= options['puppet_install']['environment'] %><% end %>
43
+ - /opt/puppetlabs/bin/puppet agent -t
44
+ <% else %>
45
+ <% end %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awstool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Burgess
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-28 00:00:00.000000000 Z
11
+ date: 2016-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,8 +72,6 @@ email:
72
72
  - nburgess@uchicago.edu
73
73
  executables:
74
74
  - awstool
75
- - console
76
- - setup
77
75
  extensions: []
78
76
  extra_rdoc_files: []
79
77
  files:
@@ -85,8 +83,6 @@ files:
85
83
  - Rakefile
86
84
  - awstools.gemspec
87
85
  - bin/awstool
88
- - bin/console
89
- - bin/setup
90
86
  - examples/awstools.yaml
91
87
  - lib/awstool.rb
92
88
  - lib/awstool/instance.rb
data/bin/console DELETED
@@ -1,14 +0,0 @@
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 DELETED
@@ -1,8 +0,0 @@
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