-
Notifications
You must be signed in to change notification settings - Fork 900
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
Pull roles from ansible galaxy before running a playbook #19079
Merged
Fryguy
merged 5 commits into
ManageIQ:master
from
carbonin:pull_roles_from_ansible_galaxy
Aug 1, 2019
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
40a2244
Use the --project-dir option of ansible-runner for playbooks
carbonin e347b0b
Allow Ansible::Content to pull requirements from the roles directory
carbonin c603ac6
Fetch roles from ansible galaxy after cloning the playbook repo
carbonin 2aba2be
Allow strings or pathnames in Ansible::Content
carbonin 6bfcc74
Move logic to fetch galaxy roles to Ansible::Runner
carbonin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -216,6 +216,7 @@ def run_via_cli(hosts, credentials, env_vars, extra_vars, tags: nil, ansible_run | |
params = runner_params(base_dir, ansible_runner_method, playbook_or_role_args, verbosity) | ||
|
||
begin | ||
fetch_galaxy_roles(playbook_or_role_args) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @carbonin This may change the nature of provider-based playbooks where they were expecting a one-time galaxy install at build time, and now it's that plus all the time. |
||
result = AwesomeSpawn.run("ansible-runner", :env => env_vars_hash, :params => params) | ||
res = response(base_dir, ansible_runner_method, result) | ||
ensure | ||
|
@@ -254,6 +255,12 @@ def runner_params(base_dir, ansible_runner_method, playbook_or_role_args, verbos | |
runner_args[:role_skip_facts] = nil if runner_args.delete(:role_skip_facts) | ||
runner_args[:ident] = "result" | ||
|
||
playbook = runner_args.delete(:playbook) | ||
if playbook | ||
runner_args[:playbook] = File.basename(playbook) | ||
runner_args[:project_dir] = File.dirname(playbook) | ||
NickLaMuro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
|
||
if verbosity.to_i > 0 | ||
v_flag = "-#{"v" * verbosity.to_i.clamp(1, 5)}" | ||
runner_args[v_flag] = nil | ||
|
@@ -286,6 +293,13 @@ def validate_params!(env_vars, extra_vars, tags, ansible_runner_method, playbook | |
raise ArgumentError, errors.join("; ") if errors.any? | ||
end | ||
|
||
def fetch_galaxy_roles(playbook_or_role_args) | ||
return unless playbook_or_role_args[:playbook] | ||
|
||
playbook_dir = File.dirname(playbook_or_role_args[:playbook]) | ||
Ansible::Content.new(playbook_dir).fetch_galaxy_roles | ||
end | ||
|
||
def credentials_info(credentials, base_dir) | ||
command_line = {} | ||
env_vars = {} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
RSpec.describe Ansible::Content do | ||
let(:content_dir) { Pathname.new(Dir.mktmpdir) } | ||
let(:roles_dir) { content_dir.join("roles") } | ||
let(:local_requirements) { content_dir.join("requirements.yml") } | ||
let(:roles_requirements) { content_dir.join("roles", "requirements.yml") } | ||
|
||
subject { described_class.new(content_dir) } | ||
|
||
after { FileUtils.rm_rf(content_dir) } | ||
|
||
describe "#fetch_galaxy_roles" do | ||
it "doesn't run anything if there is no requirements file" do | ||
expect(AwesomeSpawn).not_to receive(:run!) | ||
|
||
subject.fetch_galaxy_roles | ||
end | ||
|
||
it "runs ansible-galaxy using the local requirements file" do | ||
FileUtils.touch(local_requirements) | ||
|
||
expected_params = [ | ||
"install", | ||
:roles_path= => roles_dir, | ||
:role_file= => local_requirements | ||
] | ||
expect(AwesomeSpawn).to receive(:run!).with("ansible-galaxy", :params => expected_params) | ||
|
||
subject.fetch_galaxy_roles | ||
end | ||
|
||
it "runs ansible-runner using the roles requirements file" do | ||
FileUtils.mkdir(roles_dir) | ||
FileUtils.touch(roles_requirements) | ||
|
||
expected_params = [ | ||
"install", | ||
:roles_path= => roles_dir, | ||
:role_file= => roles_requirements | ||
] | ||
expect(AwesomeSpawn).to receive(:run!).with("ansible-galaxy", :params => expected_params) | ||
|
||
subject.fetch_galaxy_roles | ||
end | ||
|
||
it "prefers the roles requirements file" do | ||
FileUtils.mkdir(roles_dir) | ||
FileUtils.touch(roles_requirements) | ||
FileUtils.touch(local_requirements) | ||
|
||
expected_params = [ | ||
"install", | ||
:roles_path= => roles_dir, | ||
:role_file= => roles_requirements | ||
] | ||
expect(AwesomeSpawn).to receive(:run!).with("ansible-galaxy", :params => expected_params) | ||
|
||
subject.fetch_galaxy_roles | ||
end | ||
|
||
it "works with a string path" do | ||
FileUtils.touch(local_requirements) | ||
|
||
expected_params = [ | ||
"install", | ||
:roles_path= => roles_dir, | ||
:role_file= => local_requirements | ||
] | ||
expect(AwesomeSpawn).to receive(:run!).with("ansible-galaxy", :params => expected_params) | ||
|
||
described_class.new(content_dir.to_s).fetch_galaxy_roles | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@agrare This code is technically a shim for the fact that provider plugins have the requirements.yml at a different location. I'd like to get those all consistent, then this code can be simplified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, looks like only nuage and lenovo have a
content/ansible_runner/requirements.yml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume it should be in
content/ansible_runner/roles/requirements.yml
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, @agrare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ManageIQ/manageiq-providers-nuage#185
ManageIQ/manageiq-providers-lenovo#276
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#19131