forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontent.rb
54 lines (42 loc) · 1.44 KB
/
content.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module Ansible
class Content
PLUGIN_CONTENT_DIR = Rails.root.join("content", "ansible_consolidated").to_s.freeze
attr_accessor :path
def initialize(path)
@path = Pathname.new(path)
end
def fetch_galaxy_roles
return true unless requirements_file.exist?
require "awesome_spawn"
AwesomeSpawn.run!("ansible-galaxy", :params => ["install", :roles_path= => roles_dir, :role_file= => requirements_file])
end
def self.fetch_plugin_galaxy_roles
require "vmdb/plugins"
Vmdb::Plugins.ansible_runner_content.each do |plugin, content_dir|
puts "Fetching ansible galaxy roles for #{plugin.name}..."
begin
new(content_dir).fetch_galaxy_roles
puts "Fetching ansible galaxy roles for #{plugin.name}...Complete"
rescue AwesomeSpawn::CommandResultError => err
puts "Fetching ansible galaxy roles for #{plugin.name}...Failed - #{err.result.error}"
raise
end
end
end
def self.consolidate_plugin_content(dir = PLUGIN_CONTENT_DIR)
require "vmdb/plugins"
FileUtils.rm_rf(dir)
FileUtils.mkdir_p(dir)
Vmdb::Plugins.ansible_content.each do |content|
FileUtils.cp_r(Dir.glob("#{content.path}/*"), dir)
end
end
private
def roles_dir
@roles_dir ||= path.join('roles')
end
def requirements_file
@requirements_file ||= roles_dir.join('requirements.yml')
end
end
end