ansible_eyc_inventory 0.0.1

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: 1b12a2ca13744a4d7ad0257aca30e010e9136e74
4
+ data.tar.gz: d854af1b2c2afc2191f58df32b319a7b18fc013e
5
+ SHA512:
6
+ metadata.gz: 8f31c6750c6fa5ab58cb97d790d0ee6e8c7c7169d8118a266406821fdbf6b9135eeaae62d4525626f3da5efcf84f404e0a5411ac2c9519af12c13ea2ba6af0ec
7
+ data.tar.gz: a954f73c8588c4a370b03507a4289fbbe16fc8d231986f00f3121d63db6600d4bbcf4fabb0018bb5fd48b1b1caf566fd2e25d8fa98c5f755b8ff3b50515cfb88
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ansible_eyc_inventory.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Keita Urashima
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # Engine Yard Cloud Dynamic Inventory Script for Ansible
2
+
3
+ ## Installation
4
+
5
+ ```
6
+ $ gem install ansible_eyc_inventory
7
+ ```
8
+
9
+ ## Usage
10
+
11
+ ```
12
+ $ ansible_eyc_inventory
13
+ ```
14
+
15
+ ## Contributing
16
+
17
+ 1. Fork it ( https://github.com/ursm/ansible_eyc_inventory/fork )
18
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
19
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
20
+ 4. Push to the branch (`git push origin my-new-feature`)
21
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,25 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'ansible_eyc_inventory/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'ansible_eyc_inventory'
7
+ spec.version = AnsibleEYCInventory::VERSION
8
+ spec.authors = ['Keita Urashima']
9
+ spec.email = ['ursm@ursm.jp']
10
+ spec.summary = 'Engine Yard Cloud dynamic inventory script for Ansible'
11
+ spec.homepage = 'https://github.com/ursm/ansible_eyc_inventory'
12
+ spec.license = 'MIT'
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r(^bin/)) {|f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r(^(test|spec|features)/))
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_runtime_dependency 'engineyard-cloud-client'
20
+ spec.add_runtime_dependency 'thor'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.6'
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'rspec'
25
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'ansible_eyc_inventory/cli'
4
+
5
+ AnsibleEYCInventory::CLI.start
@@ -0,0 +1,51 @@
1
+ require 'engineyard-cloud-client'
2
+ require 'json'
3
+ require 'pathname'
4
+ require 'yaml'
5
+
6
+ module AnsibleEYCInventory
7
+ EYRC_PATH = Pathname.new('~/.eyrc')
8
+
9
+ class Error < StandardError; end
10
+
11
+ class << self
12
+ def print_json(env_name, account_name)
13
+ env = api.env_by_name(env_name, account_name)
14
+
15
+ json = env.instances.group_by(&:role).each_with_object({}) {|(role, instances), memo|
16
+ memo[role] = instances.map(&:hostname)
17
+ }.merge(
18
+ _meta: {
19
+ hostvars: env.instances.each_with_object({}) {|instance, memo|
20
+ memo[instance.hostname] = {
21
+ ansible_ssh_user: env.username,
22
+ eyc_amazon_id: instance.amazon_id,
23
+ eyc_availability_zone: instance.availability_zone,
24
+ eyc_status: instance.status
25
+ }
26
+ }
27
+ }
28
+ )
29
+
30
+ puts JSON.pretty_generate(json)
31
+ rescue Error => e
32
+ warn e.message
33
+
34
+ exit 1
35
+ end
36
+
37
+ def api
38
+ @api ||= EY::CloudClient.new(token: api_token)
39
+ end
40
+
41
+ private
42
+
43
+ def api_token
44
+ raise Error, "Could not find #{EYRC_PATH}. Run `ey login` and try again." unless EYRC_PATH.expand_path.exist?
45
+
46
+ YAML.load_file(EYRC_PATH.expand_path)['api_token'].tap {|token|
47
+ raise Error, "Could not find your API token from #{EYRC_PATH}. Run `ey login` and try again." unless token
48
+ }
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,46 @@
1
+ require 'ansible_eyc_inventory'
2
+ require 'thor'
3
+
4
+ module AnsibleEYCInventory
5
+ class CLI < Thor
6
+ include Thor::Actions
7
+
8
+ default_command :generate
9
+
10
+ add_runtime_options!
11
+ source_root File.expand_path('../../../templates', __FILE__)
12
+
13
+ desc 'generate', 'Generate inventory script'
14
+ option :destdir, aliases: %w(-d), default: './inventory'
15
+ def generate
16
+ choose_app.environments.each do |env|
17
+ dest = "#{options[:destdir]}/eyc_#{env.name}"
18
+
19
+ template 'inventory', dest, env_name: env.name, account_name: env.account.name
20
+ chmod dest, 0755
21
+ end
22
+ rescue Error => e
23
+ error e.message
24
+
25
+ exit 1
26
+ end
27
+
28
+ private
29
+
30
+ def choose_app
31
+ apps = AnsibleEYCInventory.api.apps.sort_by(&:hierarchy_name)
32
+
33
+ say
34
+
35
+ print_table apps.map.with_index(1) {|app, i|
36
+ [i, app.hierarchy_name, app.app_type_id]
37
+ }.unshift([nil, 'Name', 'Type'])
38
+
39
+ say
40
+
41
+ index = ask('Choose an application:', limited_to: 1.upto(apps.size).map(&:to_s))
42
+
43
+ apps[index.to_i.pred]
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module AnsibleEYCInventory
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe AnsibleEYCInventory do
4
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'ansible_eyc_inventory'
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'ansible_eyc_inventory'
4
+
5
+ AnsibleEYCInventory.print_json '<%= config[:env_name] %>', '<%= config[:account_name] %>'
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ansible_eyc_inventory
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Keita Urashima
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: engineyard-cloud-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - ursm@ursm.jp
86
+ executables:
87
+ - ansible_eyc_inventory
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - ansible_eyc_inventory.gemspec
99
+ - bin/ansible_eyc_inventory
100
+ - lib/ansible_eyc_inventory.rb
101
+ - lib/ansible_eyc_inventory/cli.rb
102
+ - lib/ansible_eyc_inventory/version.rb
103
+ - spec/ansible_eyc_inventory_spec.rb
104
+ - spec/spec_helper.rb
105
+ - templates/inventory.tt
106
+ homepage: https://github.com/ursm/ansible_eyc_inventory
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.2.2
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Engine Yard Cloud dynamic inventory script for Ansible
130
+ test_files:
131
+ - spec/ansible_eyc_inventory_spec.rb
132
+ - spec/spec_helper.rb