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

Seed Ansible Roles for Vmdb Plugins #17777

Merged
merged 6 commits into from
Aug 2, 2018
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
26 changes: 26 additions & 0 deletions lib/tasks/evm_ansible_runner.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'awesome_spawn'
require "vmdb/plugins"

namespace :evm do
namespace :ansible_runner do
desc "Seed galaxy roles for provider playbooks"
task :seed do
Vmdb::Plugins.ansible_runner_content.each do |plugin, content_dir|
puts "Seeding roles for #{plugin.name}..."

roles_path = content_dir.join('roles')
role_file = content_dir.join('requirements.yml')

params = ["install", :roles_path= => roles_path, :role_file= => role_file]

begin
AwesomeSpawn.run!("ansible-galaxy", :params => params)
puts "Seeding roles for #{plugin.name}...Complete"
rescue AwesomeSpawn::CommandResultError => err
puts "Seeding roles for #{plugin.name}...Failed - #{err.result.error}"
raise
end
end
end
end
end
11 changes: 11 additions & 0 deletions lib/vmdb/plugins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ def ansible_content
end
end

def ansible_runner_content
@ansible_runner_content ||= begin
map do |engine|
content_dir = engine.root.join("content", "ansible_tmp")
next unless File.exist?(content_dir.join("requirements.yml"))
Copy link
Member

Choose a reason for hiding this comment

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

My only concern here is that this enforces a requirements.yml. Is that ok? If it's only to be used for the purpose of galaxy stuff, then maybe we just need to rename the method, or return both things that have non-galaxy and galaxy content, if that makes sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

requirements.yml came from the galaxy docs https://docs.ansible.com/ansible/latest/reference_appendices/galaxy.html#installing-multiple-roles-from-a-file but you can use that file to seed roles from more than just galaxy. You can also include other files from within this file. I don't think you can specify multiple role files, we would have to run ansible-galaxy for each *.yml file if we wanted to do that.

Copy link
Member

@Fryguy Fryguy Aug 2, 2018

Choose a reason for hiding this comment

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

Can we reuse the content_directories method? EDIT: nvm...content_directories assumes there are multiple things inside, which in this case isn't true.

Copy link
Member Author

@agrare agrare Aug 2, 2018

Choose a reason for hiding this comment

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

content_directories would do content/ansible_tmp/* which would return every file and dir in that directory. For the purpose of seeding we only care about the role_file. We could change content_directories to take the last component as an arg and default to * but we could override with .e.g. requirements.yml

Ah didn't see your edit


[engine, content_dir]
Copy link
Member

Choose a reason for hiding this comment

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

Would prefer if this returned a Hash like some of the other ones here. Either that or create the wrapper struct like AutomateDomain or AnsibleContent.

end.compact
end
end

def automate_domains
@automate_domains ||= begin
require_relative 'plugins/automate_domain'
Expand Down