From 6f40eb16f0624dbe8d61b42c4c1d51cca0f956c2 Mon Sep 17 00:00:00 2001 From: Jason Frey Date: Tue, 2 Mar 2021 11:30:48 -0500 Subject: [PATCH] Avoid seeding ansible content in production Ansible content is already seeded at RPM build time, so to avoid the need to hit the filesystem again, we should skip this in production mode. Additionally, this adds the consolidation of ansible content to seed time, in addition to the fetching of galaxy roles. --- .../providers/embedded_ansible/seeding.rb | 8 ++++++- lib/ansible/content.rb | 23 ++++++++++++++++--- lib/tasks/evm_ansible_runner.rake | 23 +++++++------------ lib/vmdb/plugins.rb | 4 ++++ 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/app/models/manageiq/providers/embedded_ansible/seeding.rb b/app/models/manageiq/providers/embedded_ansible/seeding.rb index 4d2d1536e58..fd5cc17ed17 100644 --- a/app/models/manageiq/providers/embedded_ansible/seeding.rb +++ b/app/models/manageiq/providers/embedded_ansible/seeding.rb @@ -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 diff --git a/lib/ansible/content.rb b/lib/ansible/content.rb index 6a0c8b98d99..31b36b09f06 100644 --- a/lib/ansible/content.rb +++ b/lib/ansible/content.rb @@ -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) diff --git a/lib/tasks/evm_ansible_runner.rake b/lib/tasks/evm_ansible_runner.rake index cd928c02436..619cc6abc99 100644 --- a/lib/tasks/evm_ansible_runner.rake +++ b/lib/tasks/evm_ansible_runner.rake @@ -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 diff --git a/lib/vmdb/plugins.rb b/lib/vmdb/plugins.rb index 6c178f3b03e..4b15d44760f 100644 --- a/lib/vmdb/plugins.rb +++ b/lib/vmdb/plugins.rb @@ -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' @@ -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|