Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid seeding ansible content in production #21089

Merged
merged 1 commit into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still feel this would be better suited for /bin/update or /bin/setup

but I'm ok with this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I didn't want to rock this boat too much, so I left it...we can definitely debate dropping it from here, but I'd rather do that in a follow up.

I really don't understand the use case of why it's here in seed in the first place. From what I can tell it's for developers modifying things, but then, I don't see why they can't just call evm:ansible_runner:seed themselves.

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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note the method rename here. This was intentional, as we don't just consolidate playbooks, so the name was inaccurate and confusing.

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