diff --git a/app/models/service_ansible_playbook.rb b/app/models/service_ansible_playbook.rb index 159f93eb935..1f2706bd225 100644 --- a/app/models/service_ansible_playbook.rb +++ b/app/models/service_ansible_playbook.rb @@ -102,8 +102,10 @@ def extra_vars_from_dialog end def create_inventory_with_hosts(action, hosts) - manager(action).with_provider_connection do |connection| - connection.api.inventories.create!(:name => inventory_name(action), :organization => 1).tap do |inventory| + tower = manager(action) + tower.with_provider_connection do |connection| + miq_org = tower.provider.default_organization + connection.api.inventories.create!(:name => inventory_name(action), :organization => miq_org).tap do |inventory| hosts.split(',').each do |host| connection.api.hosts.create!(:name => host, :inventory => inventory.id) end diff --git a/app/models/service_template_ansible_playbook.rb b/app/models/service_template_ansible_playbook.rb index 921eb5d079c..6e41bac51f7 100644 --- a/app/models/service_template_ansible_playbook.rb +++ b/app/models/service_template_ansible_playbook.rb @@ -91,7 +91,7 @@ def self.build_parameter_list(name, description, info) :description => description || '', :project => playbook.configuration_script_source.manager_ref, :playbook => playbook.name, - :inventory => tower.inventory_root_groups.find_by!(:name => 'Demo Inventory').ems_ref, + :inventory => tower.provider.default_inventory, :ask_variables_on_launch => true, :ask_limit_on_launch => true, :ask_inventory_on_launch => true, diff --git a/spec/models/service_template_ansible_playbook_spec.rb b/spec/models/service_template_ansible_playbook_spec.rb index 8bfff709fb1..9c5f1a6da80 100644 --- a/spec/models/service_template_ansible_playbook_spec.rb +++ b/spec/models/service_template_ansible_playbook_spec.rb @@ -5,17 +5,14 @@ let(:script_source) { FactoryGirl.create(:configuration_script_source, :manager => ems) } - let(:inventory_root_group) { FactoryGirl.create(:inventory_root_group, :name => 'Demo Inventory') } let(:service_template_catalog) { FactoryGirl.create(:service_template_catalog) } - let(:ems) do - FactoryGirl.create(:automation_manager_ansible_tower, :inventory_root_groups => [inventory_root_group]) - end + let(:provider) { FactoryGirl.create(:provider_embedded_ansible, :default_inventory => 1) } + let(:ems) { FactoryGirl.create(:automation_manager_ansible_tower, :provider => provider) } let(:playbook) do FactoryGirl.create(:embedded_playbook, :configuration_script_source => script_source, - :manager => ems, - :inventory_root_group => inventory_root_group) + :manager => ems) end let(:job_template) do