Skip to content

Commit

Permalink
Merge pull request #21089 from Fryguy/ansible_seeding
Browse files Browse the repository at this point in the history
Avoid seeding ansible content in production
  • Loading branch information
kbrock authored Mar 4, 2021
2 parents 5f82da6 + 6f40eb1 commit 784d4f2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
8 changes: 7 additions & 1 deletion app/models/manageiq/providers/embedded_ansible/seeding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ def seed
:resource => manager
)

Ansible::Content.consolidate_plugin_playbooks
# In production mode, the RPM build takes cares of consolidating all of
# the plugin content, which will not change, so this is unnecessary.
# In development mode, changes to content will be reconsolidated on every
# seed for convenience.
unless Rails.env.production?
Ansible::Content.consolidate_plugin_content
end
end
end
end
23 changes: 20 additions & 3 deletions lib/ansible/content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,28 @@ def initialize(path)
def fetch_galaxy_roles
return true unless requirements_file.exist?

params = ["install", :roles_path= => roles_dir, :role_file= => requirements_file]
AwesomeSpawn.run!("ansible-galaxy", :params => params)
require "awesome_spawn"
AwesomeSpawn.run!("ansible-galaxy", :params => ["install", :roles_path= => roles_dir, :role_file= => requirements_file])
end

def self.consolidate_plugin_playbooks(dir = PLUGIN_CONTENT_DIR)
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)

Expand Down
23 changes: 8 additions & 15 deletions lib/tasks/evm_ansible_runner.rake
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
namespace :evm do
namespace :ansible_runner do
desc "Seed galaxy roles for provider playbooks"
desc "Seed plugin ansible content and galaxy roles"
task :seed do
require 'awesome_spawn'
require "vmdb/plugins"
require 'ansible/content'
require "ansible/content"

Vmdb::Plugins.ansible_runner_content.each do |plugin, content_dir|
content = Ansible::Content.new(content_dir)
puts "Fetching ansible galaxy roles for plugins..."
Ansible::Content.fetch_plugin_galaxy_roles
puts "Fetching ansible galaxy roles for plugins...Complete"

puts "Seeding roles for #{plugin.name}..."
begin
content.fetch_galaxy_roles
puts "Seeding roles for #{plugin.name}...Complete"
rescue AwesomeSpawn::CommandResultError => err
puts "Seeding roles for #{plugin.name}...Failed - #{err.result.error}"
raise
end
end
puts "Consolidating plugin ansible content..."
Ansible::Content.consolidate_plugin_content
puts "Consolidating plugin ansible content...Complete"
end
end
end
4 changes: 4 additions & 0 deletions lib/vmdb/plugins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def versions
details.transform_values { |v| v[:version] }
end

# Ansible content (roles) that come out-of-the-box, for use by both Automate
# and ansible-runner
def ansible_content
@ansible_content ||= begin
require_relative 'plugins/ansible_content'
Expand All @@ -52,6 +54,8 @@ def ansible_content
end
end

# Ansible content (playbooks and roles) for internal use by provider plugins,
# not exposed to Automate, and to be run by ansible_runner
def ansible_runner_content
@ansible_runner_content ||= begin
map do |engine|
Expand Down

0 comments on commit 784d4f2

Please sign in to comment.