awstool 0.1.2 → 0.2.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: dbdda7c021771785cd49640a028eec8b8551666d
4
- data.tar.gz: 862bbb43473f722000217f63258d5413c7f73979
3
+ metadata.gz: 4762dd9f95d844c3c8264fb411ee1e18be2c8ad6
4
+ data.tar.gz: 0c655be925d5b4dc251ca5af37744e087162adaf
5
5
  SHA512:
6
- metadata.gz: c86056fbedcc08aab885db7fb81f3b364b1790f357e8311c5ddf2d9003e05d28bdbc73b4e7f90bdc4f7b05aae062a48c731362f780f2f6917f5abded03837559
7
- data.tar.gz: 89925c7f1dbdea042e38c932e69923bc3970a2e11eaba7e0a13aff54ba45701e9a5cc545140f4f0f349362d6a7ed9a3d155e8b47792a6762687b2ca5cd19585e
6
+ metadata.gz: 4bc47003f5126bdb6d7adbb7c13cc894735b2a1ca69e4cede3ac5944cfe610e017021c9d4d30f7cfc805a7cecf655ef1de47bdfc65e3a95751fb56c641b0465c
7
+ data.tar.gz: 4a1b60fdc47cd3270b76ff9bf42956ce59aa43f26aa8a3d8445854e6c276069ef887257dd2576c595c5cf84c6843c38b483d1f909c5d596213f5b090ab823c7e
@@ -1,8 +1,8 @@
1
1
  key-name: mykey
2
2
  image-id: ami-foobar
3
3
  subnet-ids:
4
- - subnet-foobar
5
- - subnet-foobas
4
+ - subnet-foobar
5
+ - subnet-foobas
6
6
  security-group-ids:
7
7
  - sg-foobar
8
8
  - sg-foobaz
@@ -21,3 +21,9 @@ puppet_install:
21
21
  environment: aws
22
22
  purge_dns: true
23
23
  subnet_balance: true
24
+ rootvol_size: 10
25
+ block_devices:
26
+ xvdf:
27
+ mountpoint: /www
28
+ size: 20
29
+ filesystem: ext4
@@ -8,18 +8,18 @@ class Awstool::Instance
8
8
  provider: 'AWS',
9
9
  region: @options['region'],
10
10
  aws_access_key_id: @options['access_key_id'],
11
- aws_secret_access_key: @options['access_key'],
11
+ aws_secret_access_key: @options['access_key']
12
12
  )
13
13
  @dns = Fog::DNS.new(
14
14
  provider: 'AWS',
15
15
  aws_access_key_id: @options['access_key_id'],
16
- aws_secret_access_key: @options['access_key'],
16
+ aws_secret_access_key: @options['access_key']
17
17
  )
18
-
19
18
  end
20
19
 
21
20
  def launch
22
21
  b = binding
22
+ userdata = ERB.new(File.read(@options['userdata']), nil, '<>').result(b)
23
23
  @instance = @compute.servers.create(
24
24
  image_id: @options['image-id'],
25
25
  flavor_id: @options['instance-type'],
@@ -27,15 +27,8 @@ class Awstool::Instance
27
27
  subnet_id: @options['subnet-ids'][@options['subnet-id-index']],
28
28
  key_name: @options['key-name'],
29
29
  tags: @options['tags'],
30
- user_data: ERB.new(File.read(@options['userdata'])).result(b),
31
- block_device_mapping: [
32
- {
33
- 'DeviceName' => '/dev/sda1',
34
- 'Ebs.VolumeType' => "gp2",
35
- 'Ebs.VolumeSize' => @options['rootvol_size'],
36
- 'Ebs.DeleteOnTermination' => 'true'
37
- },
38
- ],
30
+ user_data: userdata,
31
+ block_device_mapping: map_block_devices
39
32
  )
40
33
  @instance.wait_for { ready? }
41
34
  pp @instance.reload
@@ -43,18 +36,38 @@ class Awstool::Instance
43
36
 
44
37
  def set_dns
45
38
  zone = @dns.zones.get(@options['dns-zone-id'])
46
-
47
39
  if @options['purge_dns']
48
40
  record = zone.records.find { |r| r.name == "#{@options['hostname']}." }
49
41
  if record
50
42
  record.destroy
51
43
  end
52
44
  end
53
-
54
45
  record = zone.records.create(
55
46
  value: @instance.private_ip_address,
56
47
  name: @options['hostname'],
57
48
  type: 'A'
58
49
  )
59
50
  end
51
+
52
+ private
53
+
54
+ def map_block_devices
55
+ block_device_mapping = [
56
+ {
57
+ 'DeviceName' => '/dev/sda1',
58
+ 'Ebs.VolumeType' => 'gp2',
59
+ 'Ebs.VolumeSize' => @options['rootvol_size'],
60
+ 'Ebs.DeleteOnTermination' => 'true'
61
+ }
62
+ ]
63
+ @options['block_devices'].each do |device, opts|
64
+ block_device_mapping << {
65
+ 'DeviceName' => "/dev/#{device}",
66
+ 'Ebs.VolumeType' => 'gp2',
67
+ 'Ebs.VolumeSize' => opts['size'],
68
+ 'Ebs.DeleteOnTermination' => 'true'
69
+ }
70
+ end
71
+ block_device_mapping
72
+ end
60
73
  end
@@ -84,5 +84,6 @@ class Awstool::Settings
84
84
  @options['tags']= {}
85
85
  @options['hostnames'] = []
86
86
  @options['rootvol_size'] = 8
87
+ @options['block_devices'] = []
87
88
  end
88
89
  end
@@ -1,3 +1,3 @@
1
1
  module Awstool
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -1,8 +1,8 @@
1
1
  #cloud-config
2
2
 
3
3
  bootcmd:
4
- - echo <%= @options['hostname'] %> > /etc/hostname
5
- - hostname -F /etc/hostname
4
+ - echo <%= @options['hostname'] %> > /etc/hostname
5
+ - hostname -F /etc/hostname
6
6
 
7
7
  hostname: <%= @options['hostname'] %>
8
8
  fqdn: <%= @options['hostname'] %>
@@ -11,35 +11,58 @@ manage_etc_hosts: true
11
11
  package_upgrade: true
12
12
  package_reboot_if_required: true
13
13
 
14
+ disk_setup:
15
+ <% @options['block_devices'].each do |device, opts| %>
16
+ /dev/<%= device %>:
17
+ table_type: mbr
18
+ layout: true
19
+ overwrite: true
20
+ <% end %>
21
+
22
+ fs_setup:
23
+ <% @options['block_devices'].each do |device, opts| %>
24
+ - label: None
25
+ filesystem: <%= opts['filesystem'] %>
26
+ device: /dev/<%= device %>1
27
+ partition: auto
28
+ <% end %>
29
+
30
+ mounts:
31
+ <% @options['block_devices'].each do |device, opts| %>
32
+ - [ /dev/<%= device %>1, <%= opts['mountpoint'] %>, <%= opts['filesystem'] %>, 'defaults,noatime' ]
33
+ <% end %>
34
+
35
+ mount_default_fields: [ None, None, "ext3", "defaults,noatime", "0","2" ]
36
+
14
37
  write_files:
15
38
  <% if @options['puppet_install']['csr_attributes'] %>
16
- - content: |
17
- ---
18
- custom_attributes:
19
- 1.2.840.113549.1.9.7: <%= @options['puppet_install']['csr_attributes'] %>
20
- path: /etc/puppetlabs/puppet/csr_attributes.yaml
21
- permissions: 0600
39
+ - content: |
40
+ ---
41
+ custom_attributes:
42
+ 1.2.840.113549.1.9.7: <%= @options['puppet_install']['csr_attributes'] %>
43
+ path: /etc/puppetlabs/puppet/csr_attributes.yaml
44
+ permissions: 0600
22
45
  <% end %>
23
46
  <% @options['facts'].each do |fact, value| %>
24
- - content: |
25
- ---
26
- <%= fact %>: <%= value %>
27
- path: /opt/puppetlabs/facter/facts.d/<%= fact %>.yaml
28
- permissions: '0644'
47
+ - content: |
48
+ ---
49
+ <%= fact %>: <%= value %>
50
+ path: /opt/puppetlabs/facter/facts.d/<%= fact %>.yaml
51
+ permissions: '0644'
29
52
  <% end %>
30
-
53
+
31
54
  <% if @options['puppet_install'] %>
32
55
  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
56
+ <% if @options['puppet_install']['package_manager'] == 'apt-get' %>
57
+ - wget https://apt.puppetlabs.com/<%= @options['puppet_install']['repo_package'] %>
58
+ - dpkg -i /<%= @options['puppet_install']['repo_package'] %>
59
+ - apt-get update
60
+ - apt-get -y install puppet-agent
61
+ <% elsif @options['puppet_install']['package_manager'] == 'yum' %>
62
+ - rpm -ivh https://yum.puppetlabs.com/<%= @options['puppet_install']['repo_package'] %>
63
+ - yum -y install puppet-agent
64
+ <% end %>
65
+ - /opt/puppetlabs/bin/puppet agent -t --waitforcert 5 --server <%= @options['puppet_install']['server'] %> <% if @options['puppet_install']['environment'] %> --environment <%= @options['puppet_install']['environment'] %><% end %>
66
+ - /opt/puppetlabs/bin/puppet agent -t
44
67
  <% else %>
45
68
  <% 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.1.2
4
+ version: 0.2.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-30 00:00:00.000000000 Z
11
+ date: 2016-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler