tsudura 0.1.7 → 0.1.8

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: 13dfb65a1d975c7bf415a9584a22a69ff2307b3f
4
- data.tar.gz: e5f47a5185e211193610d732219990eabcea366d
3
+ metadata.gz: 56a4955ff27b07868427adff391a2c354728b695
4
+ data.tar.gz: 8a3fa23722dcb6c0d4c80b790db0c932b3370cc3
5
5
  SHA512:
6
- metadata.gz: 24009755f26a5ee60d759b07fe95cf5a3a7a22f00c4540b728ba9d9a2d97c009df08506ffdd4bac778652ac943327a540eec2232acb8a2d3c5446984c061531f
7
- data.tar.gz: 75462483d1774d6c06e8c02a6358ebde5eba59b92db4ea4b85dd5cfb7025f23400b521f91b6f10a165ef19df696ec9e2ff92c0d97400f500c5ac4df59c8fbff2
6
+ metadata.gz: 205d6370da4f3f30048c273cba79e9bd650b7fd73218e33704fa800af2ba6617bdbf4bcbaedaa1837b11ccd5494c3ab2e95bad56a43a8cfe433119b2b15050f7
7
+ data.tar.gz: ba6d4ab8c6e10642409ccc4b85aee214846a514e87cf4fbfaed381377f5903d1adabd1b458dc83c8d2ad070af985bc3d68d0b0dc90d2fe6e8dfc2584ea2abfd9
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  /vendor/bundle
11
+ .envrc
data/.travis.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.2.2
4
+ - 2.2.3
4
5
  before_script:
5
6
  - export COVERAGE=true
6
7
  script:
@@ -7,16 +7,15 @@ module Tsudura::Aws
7
7
  @config = config
8
8
  @timestamp = timestamp
9
9
  end
10
+
11
+ def options
12
+ option = base_option
13
+ option[:iam_instance_profile] = @config[:iam_instance_profile] if @config[:iam_instance_profile]
14
+ option
15
+ end
10
16
 
11
17
  def create
12
- @new_launch_config = autoscaling.create_launch_configuration(
13
- image_id: @image_id,
14
- key_name: @config[:key_name],
15
- user_data: Base64.encode64(@config[:user_data_script]),
16
- instance_type: @config[:instance_type],
17
- security_groups: [@config[:security_group_id]],
18
- launch_configuration_name: "#{@config[:service]}-#{short_env}-#{@timestamp}",
19
- )
18
+ @new_launch_config = autoscaling.create_launch_configuration(options)
20
19
  end
21
20
 
22
21
  def delete
@@ -50,5 +49,16 @@ module Tsudura::Aws
50
49
  autoscaling.describe_launch_configurations.each_page { |i| tmp.concat i.launch_configurations }
51
50
  tmp.select { |i| i[:launch_configuration_name] =~ /#{@config[:service]}-#{short_env}/ }.map(&:launch_configuration_name)
52
51
  end
52
+
53
+ def base_option
54
+ {
55
+ image_id: @image_id,
56
+ key_name: @config[:key_name],
57
+ user_data: Base64.encode64(@config[:user_data_script]),
58
+ instance_type: @config[:instance_type],
59
+ security_groups: [@config[:security_group_id]],
60
+ launch_configuration_name: "#{@config[:service]}-#{short_env}-#{@timestamp}",
61
+ }
62
+ end
53
63
  end
54
64
  end
@@ -0,0 +1,11 @@
1
+ module Tsudura::Provisioner
2
+ module Ansible
3
+ class Command
4
+ def self.exec(config)
5
+ Open3.popen3(CommandGenerator.new(config).generate) do |i, o, e, w|
6
+ o.each do |line| puts line end
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,44 @@
1
+ module Tsudura::Provisioner
2
+ module Ansible
3
+ class CommandGenerator
4
+ def initialize(config)
5
+ @config = config
6
+ end
7
+
8
+ def generate
9
+ exec_command = []
10
+ exec_command << base_command
11
+ exec_command << vault_option if use_vault_option?
12
+ exec_command.join(" ")
13
+ end
14
+
15
+ def use_vault_option?
16
+ @config[:vault_password] ? true : false
17
+ end
18
+
19
+ private
20
+
21
+ def base_command
22
+ "ansible-playbook #{@config[:playbook_path]} -i #{@config[:inventory_file]}"
23
+ end
24
+
25
+ def vault_option
26
+ create_vault_password_file
27
+ vault_password_file_option
28
+ end
29
+
30
+ def create_vault_password_file
31
+ tmp_password_file << @config[:vault_password]
32
+ tmp_password_file.close
33
+ end
34
+
35
+ def vault_password_file_option
36
+ "--vault-password-file #{tmp_password_file.path}"
37
+ end
38
+
39
+ def tmp_password_file
40
+ @tmp_password_file ||= Tempfile.new("tsudura.#{@config[:service]}")
41
+ end
42
+ end
43
+ end
44
+ end
@@ -9,7 +9,7 @@ module Tsudura::Runners
9
9
  end
10
10
 
11
11
  def provision
12
- Tsudura::Provisioner::Ansible.new(@config).provision!
12
+ Tsudura::Provisioner::Ansible::Command.exec @config
13
13
  end
14
14
 
15
15
  def create_ami
@@ -1,3 +1,3 @@
1
1
  module Tsudura
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
data/lib/tsudura.rb CHANGED
@@ -25,4 +25,6 @@ require "tsudura/aws/ami"
25
25
  require "tsudura/aws/auto_scale"
26
26
  require "tsudura/aws/launch_config"
27
27
  require "tsudura/aws/launch_instance"
28
- require "tsudura/provisioner/ansible"
28
+
29
+ require "tsudura/provisioner/ansible/command"
30
+ require "tsudura/provisioner/ansible/command_generator"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tsudura
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - onigra
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-28 00:00:00.000000000 Z
11
+ date: 2016-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -194,7 +194,8 @@ files:
194
194
  - lib/tsudura/config_parser.rb
195
195
  - lib/tsudura/env_prefix.rb
196
196
  - lib/tsudura/progress_bar.rb
197
- - lib/tsudura/provisioner/ansible.rb
197
+ - lib/tsudura/provisioner/ansible/command.rb
198
+ - lib/tsudura/provisioner/ansible/command_generator.rb
198
199
  - lib/tsudura/runner.rb
199
200
  - lib/tsudura/runners/normal_runner.rb
200
201
  - lib/tsudura/runners/packer_plus_runner.rb
@@ -225,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
226
  version: '0'
226
227
  requirements: []
227
228
  rubyforge_project:
228
- rubygems_version: 2.4.5
229
+ rubygems_version: 2.4.5.1
229
230
  signing_key:
230
231
  specification_version: 4
231
232
  summary: Update ami and launch_config and auto scaling group like packer.
@@ -1,48 +0,0 @@
1
- module Tsudura::Provisioner
2
- class Ansible
3
- def initialize(config)
4
- @config = config
5
- end
6
-
7
- def provision!
8
- command = base_command
9
-
10
- if use_vault_option?
11
- command << add_vault_option
12
- end
13
-
14
- Open3.popen3 command do |i, o, e, w|
15
- o.each do |line| puts line end
16
- end
17
- ensure
18
- remove_vault_password_file if use_vault_option?
19
- end
20
-
21
- private
22
-
23
- def base_command
24
- "ansible-playbook #{@config[:playbook_path]} -i #{@config[:inventory_file]}"
25
- end
26
-
27
- def use_vault_option?
28
- @config[:vault_password] ? true : false
29
- end
30
-
31
- def add_vault_option
32
- create_vault_password_file
33
- vault_option
34
- end
35
-
36
- def vault_option
37
- " --vault-password-file tmp_password_file"
38
- end
39
-
40
- def create_vault_password_file
41
- File.open("tmp_password_file", "w") { |f| f.puts @config[:vault_password] }
42
- end
43
-
44
- def remove_vault_password_file
45
- FileUtils.rm "tmp_password_file"
46
- end
47
- end
48
- end