appforce-spawn 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.appforce.example +4 -0
  3. data/.gitignore +8 -0
  4. data/Gemfile +17 -0
  5. data/History +85 -0
  6. data/README.md +144 -0
  7. data/ansible/README.md +31 -0
  8. data/ansible/common.yml +6 -0
  9. data/ansible/roles/common/tasks/.keep +0 -0
  10. data/ansible/roles/common/tasks/active_users.yml +23 -0
  11. data/ansible/roles/common/tasks/groups.yml +28 -0
  12. data/ansible/roles/common/tasks/inactive_users.yml +26 -0
  13. data/ansible/roles/common/tasks/main.yml +5 -0
  14. data/ansible/roles/common/tasks/setup.yml +6 -0
  15. data/ansible/roles/scout/tasks/.keep +0 -0
  16. data/ansible/roles/scout/tasks/install.yml +28 -0
  17. data/ansible/roles/scout/tasks/main.yml +2 -0
  18. data/ansible/roles/scout/vars/.keep +0 -0
  19. data/ansible/rvm.yml +13 -0
  20. data/ansible/scout.yml +6 -0
  21. data/ansible/site.yml +4 -0
  22. data/appforce-spawn.gemspec +24 -0
  23. data/bin/appforce-spawn +161 -0
  24. data/lib/appforce-spawn.rb +1 -0
  25. data/lib/appforce/config.rb +50 -0
  26. data/lib/appforce/logger.rb +25 -0
  27. data/lib/appforce/spawn.rb +312 -0
  28. data/lib/appforce/spawn/api.rb +4 -0
  29. data/lib/appforce/spawn/api/call.rb +217 -0
  30. data/lib/appforce/spawn/exceptions.rb +30 -0
  31. data/lib/appforce/spawn/runner.rb +143 -0
  32. data/lib/appforce/spawn/template.rb +102 -0
  33. data/lib/appforce/spawn/version.rb +10 -0
  34. data/spec/api_call_spec.rb +380 -0
  35. data/spec/config_spec.rb +51 -0
  36. data/spec/fixtures/all_host_data.json +12 -0
  37. data/spec/fixtures/appforce_config.yml +4 -0
  38. data/spec/fixtures/fake_private_key.yml +2 -0
  39. data/spec/fixtures/host_scout_vars.yml +10 -0
  40. data/spec/fixtures/hosts +8 -0
  41. data/spec/fixtures/inactive_users.yml +3 -0
  42. data/spec/fixtures/malformed_appforce_config.yml +4 -0
  43. data/spec/fixtures/private_key_vars.yml +4 -0
  44. data/spec/fixtures/scout_main.yml +2 -0
  45. data/spec/fixtures/users.yml +6 -0
  46. data/spec/fixtures/vars.yml +4 -0
  47. data/spec/logger_spec.rb +85 -0
  48. data/spec/runner_spec.rb +308 -0
  49. data/spec/spec_helper.rb +53 -0
  50. data/spec/template_spec.rb +160 -0
  51. data/spec/version_spec.rb +9 -0
  52. data/tmp/.keep +0 -0
  53. metadata +151 -0
@@ -0,0 +1,4 @@
1
+ require 'appforce/config'
2
+ require 'appforce/logger'
3
+ require 'appforce/spawn/exceptions'
4
+ require 'appforce/spawn/api/call'
@@ -0,0 +1,217 @@
1
+ module Appforce
2
+ module Spawn
3
+ module Api
4
+ class Call
5
+ require 'highline/import'
6
+
7
+ def self.get_clients
8
+ url = "#{base_api_url}client/list?#{token_param}"
9
+ logger.debug "[#{self.name}##{__method__.to_s}] URL: #{url}"
10
+ make_api_call(url)
11
+ end
12
+
13
+ def self.get_hosts(*args)
14
+ opts = args[1]
15
+ unless opts[:client_api_name]
16
+ logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingParameters -- Missing Client API Name"
17
+ raise Appforce::Spawn::MissingParameters, "Missing Client API Name"
18
+ end
19
+
20
+ url = "#{client_url(opts[:client_api_name])}/hosts?#{token_param}"
21
+ logger.debug "[#{self.name}##{__method__.to_s}] URL: #{url}"
22
+ make_api_call(url)
23
+ end
24
+
25
+ def self.get_active_users(*args)
26
+ opts = args[1]
27
+ unless opts[:client_api_name]
28
+ logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingParameters -- Missing Client API Name"
29
+ raise Appforce::Spawn::MissingParameters, "Missing Client API Name"
30
+ end
31
+
32
+ url = "#{client_url(opts[:client_api_name])}/users/active.yml?#{token_param}"
33
+ logger.debug "[#{self.name}##{__method__.to_s}] URL: #{url}"
34
+ make_api_call(url)
35
+ end
36
+
37
+ def self.get_inactive_users(*args)
38
+ opts = args[1]
39
+ unless opts[:client_api_name]
40
+ logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingParameters -- Missing Client API Name"
41
+ raise Appforce::Spawn::MissingParameters, "Missing Client API Name"
42
+ end
43
+
44
+ url = "#{client_url(opts[:client_api_name])}/users/inactive.yml?#{token_param}"
45
+ logger.debug "[#{self.name}##{__method__.to_s}] URL: #{url}"
46
+ make_api_call(url)
47
+ end
48
+
49
+ def self.get_vars(*args)
50
+ opts = args[1]
51
+ unless opts[:client_api_name]
52
+ logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingParameters -- Missing Client API Name"
53
+ raise Appforce::Spawn::MissingParameters, "Missing Client API Name"
54
+ end
55
+
56
+ url = "#{client_url(opts[:client_api_name])}/vars.yml?#{token_param}"
57
+ logger.debug "[#{self.name}##{__method__.to_s}] URL: #{url}"
58
+ make_api_call(url)
59
+ end
60
+
61
+ def self.get_main_scout(*args)
62
+ opts = args[1]
63
+ unless opts[:client_api_name]
64
+ logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingParameters -- Missing Client API Name"
65
+ raise Appforce::Spawn::MissingParameters, "Missing Client API Name"
66
+ end
67
+
68
+ url = "#{client_url(opts[:client_api_name])}/scout.yml?#{token_param}"
69
+ logger.debug "[#{self.name}##{__method__.to_s}] URL: #{url}"
70
+ make_api_call(url)
71
+ end
72
+
73
+ def self.get_private_key(*args)
74
+ opts = args[1]
75
+ unless opts[:client_api_name]
76
+ logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingParameters -- Missing Client API Name"
77
+ raise Appforce::Spawn::MissingParameters, "Missing Client API Name"
78
+ end
79
+
80
+ url = "#{client_url(opts[:client_api_name])}/private_key.pem?#{token_param}"
81
+ logger.debug "[#{self.name}##{__method__.to_s}] URL: #{url}"
82
+ make_api_call(url)
83
+ end
84
+
85
+ def self.get_host_scout_vars(*args)
86
+ opts = args[1]
87
+ unless opts[:host_api_name]
88
+ logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingParameters -- Missing Host API Name"
89
+ raise Appforce::Spawn::MissingParameters, "Missing Host API Name"
90
+ end
91
+
92
+ url = "#{host_url(opts[:host_api_name])}/scout.yml?#{token_param}"
93
+ logger.debug "[#{self.name}##{__method__.to_s}] URL: #{url}"
94
+ make_api_call(url)
95
+ end
96
+
97
+ def self.get_all_host_data(*args)
98
+ opts = args[1]
99
+ unless opts[:client_api_name]
100
+ logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingParameters -- Missing Client API Name"
101
+ raise Appforce::Spawn::MissingParameters, "Missing Client API Name"
102
+ end
103
+
104
+ url = "#{client_url(opts[:client_api_name])}/all_host_data.json?#{token_param}"
105
+ logger.debug "[#{self.name}##{__method__.to_s}] URL: #{url}"
106
+ make_api_call(url)
107
+ end
108
+
109
+ def self.list_clients
110
+ resp = get_clients
111
+ puts Appforce::Logger.header("Client List")
112
+ resp.each do |item|
113
+ printf " Client: %-16s API Name: %s\n", item['name'], item['api_name']
114
+ end
115
+ puts Appforce::Logger.footer
116
+ end
117
+
118
+ def self.list_hosts(*args)
119
+ resp = get_all_host_data(*args)
120
+ puts Appforce::Logger.header("Host List")
121
+ i = 1
122
+ resp.each do |item|
123
+ printf " #{i} - '%s' host: %s ip: %s\n", item['desc'], item['hostname'], item['ip']
124
+ i += 1
125
+ end
126
+ puts Appforce::Logger.footer
127
+ resp
128
+ end
129
+
130
+ def self.ssh_to_host(*args)
131
+ hosts = list_hosts(*args)
132
+ input = HighLine.ask("\nWhich host to ssh to? ", Integer) { |q| q.in = 1..hosts.count }
133
+ machine = hosts[input - 1]
134
+
135
+ $stderr.print "\n"
136
+ logger.info "Establishing SSH seesion as '#{machine['username']}' to #{machine['desc']}"
137
+ logger.debug "SSH command: #{ssh_cmd(machine)}"
138
+
139
+ pid = fork {
140
+ exec ssh_cmd(machine)
141
+ }
142
+ Process.wait pid
143
+
144
+ $stderr.print "\n"
145
+ logger.info "SSH session terminated."
146
+ end
147
+
148
+ def self.ping(*args)
149
+ url = "#{base_api_url}ping?#{token_param}"
150
+ logger.debug "[#{self.name}##{__method__.to_s}] URL: #{url}"
151
+ make_api_call("#{base_api_url}ping?#{token_param}")
152
+ end
153
+
154
+ def self.latest_version(*args)
155
+ url = rubygem_latest_version_url
156
+ logger.debug "[#{self.name}##{__method__.to_s}] URL: #{url}"
157
+ resp = make_api_call(url)
158
+ resp['version']
159
+ end
160
+
161
+ private
162
+
163
+ def self.ssh_cmd(info)
164
+ "ssh #{info['username']}@#{info[info['method']]}"
165
+ end
166
+
167
+ def self.base_api_url
168
+ "#{Appforce::Config.config.api_host}/#{Appforce::Config.config.api_version}/"
169
+ end
170
+
171
+ def self.client_url(client_api_name)
172
+ "#{base_api_url}client/#{client_api_name}"
173
+ end
174
+
175
+ def self.host_url(host_api_name)
176
+ "#{base_api_url}host/#{host_api_name}"
177
+ end
178
+
179
+ def self.token_param
180
+ "token=#{Appforce::Config.config.api_token}"
181
+ end
182
+
183
+ def self.rubygem_latest_version_url
184
+ "https://rubygems.org/api/v1/versions/appforce-spawn/latest.json"
185
+ end
186
+
187
+ def self.make_api_call(url)
188
+ begin
189
+ resp = HTTParty.get(url)
190
+ rescue
191
+ logger.fatal "[#{self.name}##{__method__.to_s}] Appforce::Spawn::API::CallFailure - API Failed to Return for URL: #{url}"
192
+ raise Appforce::Spawn::API::CallFailure, "API Failed to Return."
193
+ end
194
+
195
+ case resp.code
196
+ when 200
197
+ resp
198
+ when 401
199
+ logger.fatal "[#{self.name}##{__method__.to_s}] Appforce::Spawn::API::UnauthorizedAccess -- Invalid API Access Token -- URL: #{url}"
200
+ raise Appforce::Spawn::API::UnauthorizedAccess, "Invalid API Access Token"
201
+ when 404
202
+ logger.fatal "[#{self.name}##{__method__.to_s}] -- Appforce::Spawn::API::NotFound -- API Route Not Found -- URL: #{url}"
203
+ raise Appforce::Spawn::API::NotFound, "API Route Not Found"
204
+ when 500...600
205
+ logger.fatal "[#{self.name}##{__method__.to_s}] -- Appforce::Spawn::API::Unavailable -- API Service Unavailable -- URL: #{url}"
206
+ raise Appforce::Spawn::API::Unavailable, "API Service Unavailable"
207
+ end
208
+ end
209
+
210
+ def self.logger
211
+ Appforce::Logger.logger
212
+ end
213
+
214
+ end
215
+ end
216
+ end
217
+ end
@@ -0,0 +1,30 @@
1
+ module Appforce
2
+ module Spawn
3
+
4
+ class Error < StandardError; end
5
+
6
+ class UnknownClient < Error; end
7
+
8
+ class ConfigFileParseError < Error; end
9
+
10
+ class MissingParameters < Error; end
11
+
12
+ class MissingFile < Error; end
13
+
14
+ class MissingDependency < Error; end
15
+
16
+ class NotYetImplemented < Error; end
17
+
18
+ module API
19
+ class CallFailure < Error; end
20
+
21
+ class UnauthorizedAccess < Error; end
22
+
23
+ class NotFound < Error; end
24
+
25
+ class Unavailable < Error; end
26
+
27
+ class NotYetImplemented < Error; end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,143 @@
1
+ module Appforce
2
+ module Spawn
3
+ class Runner
4
+ require 'open3'
5
+
6
+ MINIMUM_ANSIBLE_VERSION = "1.8.3"
7
+
8
+ def self.run_playbook
9
+ logger.info "[#{self.name}##{__method__.to_s}] Start running playbook."
10
+ logger.debug "[#{self.name}##{__method__.to_s}] ansible_command: #{ansible_command}"
11
+ system "#{ansible_command}"
12
+ logger.info "[#{self.name}##{__method__.to_s}] Playbook run complete."
13
+ end
14
+
15
+ def self.run_dryrun
16
+ logger.info "[#{self.name}##{__method__.to_s}] Start running dry-run of playbook."
17
+ logger.debug "[#{self.name}##{__method__.to_s}] ansible_dryrun_command: #{ansible_command} --check --diff"
18
+ system "#{ansible_command} --check --diff"
19
+ logger.info "[#{self.name}##{__method__.to_s}] Playbook dry-run complete."
20
+ end
21
+
22
+ def self.display_ansible_command
23
+ logger.info "[#{self.name}##{__method__.to_s}] Ansible command to run playbook for this Client is:\n -- #{ansible_command}"
24
+ end
25
+
26
+ def self.ansible_ping
27
+ logger.info "[#{self.name}##{__method__.to_s}] Start running ansible ping."
28
+ logger.debug "[#{self.name}##{__method__.to_s}] ansible_ping_command: #{ansible_ping_command} --check --diff"
29
+ system "#{ansible_ping_command}"
30
+ logger.info "[#{self.name}##{__method__.to_s}] Ansible ping complete."
31
+ end
32
+
33
+ def self.display_ansible_ping_command
34
+ logger.info "[#{self.name}##{__method__.to_s}] Ansible command to ping this Client is:\n -- #{ansible_ping_command}"
35
+ end
36
+
37
+ def self.can_run?
38
+ # validate stuff first
39
+ check_dependencies
40
+ unless File.exist?('./vars.yml')
41
+ logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingFile -- Missing 'vars.yml' file"
42
+ raise Appforce::Spawn::MissingFile, "Missing 'vars.yml' file"
43
+ end
44
+ unless File.exist?('./hosts')
45
+ logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingFile -- Missing 'hosts' file"
46
+ raise Appforce::Spawn::MissingFile, "Missing 'hosts' file"
47
+ end
48
+ unless File.exist?('./active_users.yml')
49
+ logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingFile -- Missing 'active_users.yml' file"
50
+ raise Appforce::Spawn::MissingFile, "Missing 'active_users.yml' file"
51
+ end
52
+ unless File.exist?('./inactive_users.yml')
53
+ logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingFile -- Missing 'inactive_users.yml' file"
54
+ raise Appforce::Spawn::MissingFile, "Missing 'inactive_users.yml' file"
55
+ end
56
+ true
57
+ end
58
+
59
+ def self.check_dependencies
60
+ # ansible install
61
+ unless ansible_installed?
62
+ logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingDependency -- Missing 'ansible' executable."
63
+ raise Appforce::Spawn::Dependency, "Missing 'ansible' executable"
64
+ end
65
+
66
+ # ansible version
67
+ unless good_ansible_version?
68
+ str = `ansible --version`
69
+ version_str = /^ansible\s(\d+\.\d+\.\d+)$/.match(str)[1].tr('.','')
70
+ logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingDependency -- Insufficient 'ansible' version: #{version_str} < #{MINIMUM_ANSIBLE_VERSION}"
71
+ raise Appforce::Spawn::Dependency, "Insufficient 'ansible' version: #{version_str} < #{MINIMUM_ANSIBLE_VERSION}"
72
+ end
73
+
74
+ # ansible rvm_io.rvm1-ruby galaxy install
75
+ unless rvm_galaxy_installed?
76
+ logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingDependency -- Missing 'rvm_io.rvm1-ruby' galaxy role."
77
+ logger.info "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingDependency -- Run 'ansible-galaxy install rvm_io.rvm1-ruby' to install role"
78
+ raise Appforce::Spawn::Dependency, "Missing 'rvm_io.rvm1-ruby' galaxy role"
79
+ end
80
+
81
+ true
82
+ end
83
+
84
+ private
85
+
86
+ def self.ansible_installed?
87
+ ansible = `which ansible`
88
+ /ansible$/.match(ansible)
89
+ end
90
+
91
+ def self.good_ansible_version?
92
+ str = `ansible --version`
93
+ version_str = /^ansible\s(\d+\.\d+\.\d+)$/.match(str)[1].tr('.','')
94
+ return true if version_str.to_i >= MINIMUM_ANSIBLE_VERSION.tr('.','').to_i
95
+ nil
96
+ end
97
+
98
+ def self.rvm_galaxy_installed?
99
+ galaxy = `ansible-galaxy list`
100
+ /^-\srvm_io.rvm1-ruby,\sv1\.3/.match(galaxy)
101
+ end
102
+
103
+ def self.ansible_command
104
+ # ansible-playbook -i hosts site.yml --extra-vars="ansible_user={{ ansible_user }} users_file=./users.yml"
105
+ begin
106
+ vars = YAML::load(File.open('./vars.yml'))
107
+ rescue Exception => e
108
+ logger.fatal "[#{self.name}##{__method__.to_s}] Appforce::Spawn::Runner::VarsFileError"\
109
+ " -- 'vars.yml' file appears to be malformed -- #{e}"
110
+ raise e
111
+ end
112
+
113
+ if vars['ansible_private_key']
114
+ "ansible-playbook -i hosts site.yml --private-key=./private_key.pem --extra-vars='ansible_user=#{vars['ansible_user']} active_users_file=./active_users.yml inactive_users_file=./inactive_users.yml'"
115
+ else
116
+ "ansible-playbook -i hosts site.yml --extra-vars='ansible_user=#{vars['ansible_user']} active_users_file=./active_users.yml inactive_users_file=./inactive_users.yml'"
117
+ end
118
+ end
119
+
120
+ def self.ansible_ping_command
121
+ # ansible all -m ping -i hosts -u ansible
122
+ begin
123
+ vars = YAML::load(File.open('./vars.yml'))
124
+ rescue Exception => e
125
+ logger.fatal "[#{self.name}##{__method__.to_s}] Appforce::Spawn::Runner::VarsFileError"\
126
+ " -- 'vars.yml' file appears to be malformed -- #{e}"
127
+ raise e
128
+ end
129
+
130
+ if vars['ansible_private_key']
131
+ "ansible all -m ping -i hosts --private-key=./private_key.pem -u #{vars['ansible_user']}"
132
+ else
133
+ "ansible all -m ping -i hosts -u #{vars['ansible_user']}"
134
+ end
135
+ end
136
+
137
+ def self.logger
138
+ Appforce::Logger.logger
139
+ end
140
+
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,102 @@
1
+ module Appforce
2
+ module Spawn
3
+ class Template
4
+ require 'fileutils'
5
+
6
+ def self.create_dirs(*args)
7
+ opts = args[1]
8
+ unless opts[:client_api_name]
9
+ logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingParameters -- Missing Client API Name"
10
+ raise Appforce::Spawn::MissingParameters, "Missing Client API Name"
11
+ end
12
+ dir = "#{ansible_dest_path(opts[:client_api_name])}"
13
+ logger.info "[#{self.name}##{__method__.to_s}] Creating directory: #{dir}"
14
+ begin
15
+ FileUtils.mkdir(dir)
16
+ rescue Errno::EEXIST
17
+ logger.warn "[#{self.name}##{__method__.to_s}] Directory (#{dir}) already exists."
18
+ end
19
+ end
20
+
21
+ def self.copy_template(*args)
22
+ opts = args[1]
23
+ unless opts[:client_api_name]
24
+ logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingParameters -- Missing Client API Name"
25
+ raise Appforce::Spawn::MissingParameters, "Missing Client API Name"
26
+ end
27
+ logger.info "[#{self.name}##{__method__.to_s}] Copying files from Template..."
28
+ FileUtils.cp_r("#{ansible_source_path}/.", "#{ansible_dest_path(opts[:client_api_name])}")
29
+ end
30
+
31
+ def self.download_files(*args)
32
+ opts = args[1]
33
+ unless opts[:client_api_name]
34
+ logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingParameters -- Missing Client API Name"
35
+ raise Appforce::Spawn::MissingParameters, "Missing Client API Name"
36
+ end
37
+
38
+ logger.info "[#{self.name}##{__method__.to_s}] Pulling Hosts file for Client '#{opts[:client_api_name]}'"
39
+ write_to_file(Appforce::Spawn::Api::Call.get_hosts(*args), "#{ansible_dest_path(opts[:client_api_name])}/hosts")
40
+ logger.info "[#{self.name}##{__method__.to_s}] Pulling Active Users file for Client '#{opts[:client_api_name]}'"
41
+ write_to_file(Appforce::Spawn::Api::Call.get_active_users(*args), "#{ansible_dest_path(opts[:client_api_name])}/active_users.yml")
42
+ logger.info "[#{self.name}##{__method__.to_s}] Pulling Inactive Users file for Client '#{opts[:client_api_name]}'"
43
+ write_to_file(Appforce::Spawn::Api::Call.get_inactive_users(*args), "#{ansible_dest_path(opts[:client_api_name])}/inactive_users.yml")
44
+ logger.info "[#{self.name}##{__method__.to_s}] Pulling Vars file for Client '#{opts[:client_api_name]}'"
45
+ write_to_file(Appforce::Spawn::Api::Call.get_vars(*args), "#{ansible_dest_path(opts[:client_api_name])}/vars.yml")
46
+ logger.info "[#{self.name}##{__method__.to_s}] Pulling Main Scout file for Client '#{opts[:client_api_name]}'"
47
+ write_to_file(Appforce::Spawn::Api::Call.get_main_scout(*args), "#{ansible_dest_path(opts[:client_api_name])}/roles/scout/vars/main.yml")
48
+ logger.info "[#{self.name}##{__method__.to_s}] Pulling Scout Host Data for Client '#{opts[:client_api_name]}'"
49
+ write_to_file(Appforce::Spawn::Api::Call.get_private_key(*args), "#{ansible_dest_path(opts[:client_api_name])}/private_key.pem")
50
+ logger.info "[#{self.name}##{__method__.to_s}] Pulling Private Key Data for Client '#{opts[:client_api_name]}'"
51
+ File.chmod(0600, "#{ansible_dest_path(opts[:client_api_name])}/private_key.pem")
52
+
53
+ host_data = Appforce::Spawn::Api::Call.get_all_host_data(*args)
54
+ host_data.each do |host|
55
+ if host['scout'] == 'true'
56
+ filename = "#{host[host['method']]}.yml"
57
+ logger.info "[#{self.name}##{__method__.to_s}] Pulling Scout Host Data for Host '#{host[host['method']]}'"
58
+ args[1][:host_api_name] = host['id']
59
+ write_to_file(Appforce::Spawn::Api::Call.get_host_scout_vars(*args), "#{ansible_dest_path(opts[:client_api_name])}/roles/scout/vars/#{filename}")
60
+ args[1].delete(:host_api_name)
61
+ end
62
+ end
63
+
64
+ end
65
+
66
+ def self.run_path
67
+ Dir.pwd
68
+ end
69
+
70
+ def self.gem_path
71
+ File.expand_path(File.dirname(__FILE__))
72
+ end
73
+
74
+ def self.ansible_source_path
75
+ File.join(gem_path, '../../../ansible')
76
+ end
77
+
78
+ def self.ansible_dest_path(client_api_name)
79
+ "#{run_path}/#{client_api_name}"
80
+ end
81
+
82
+ def self.write_to_file(data, path)
83
+ begin
84
+ file = File.open(path, "w")
85
+ file.write(data)
86
+ rescue IOError => e
87
+ logger.fatal "[#{self.name}##{__method__.to_s}] Exception writing to file '#{path}' -- #{e}"
88
+ raise e
89
+ ensure
90
+ file.close unless file == nil
91
+ end
92
+ end
93
+
94
+ private
95
+
96
+ def self.logger
97
+ Appforce::Logger.logger
98
+ end
99
+
100
+ end
101
+ end
102
+ end