diff --git a/app/models/service_ansible_playbook.rb b/app/models/service_ansible_playbook.rb index 0ca6ec069f7..c5458f552f9 100644 --- a/app/models/service_ansible_playbook.rb +++ b/app/models/service_ansible_playbook.rb @@ -13,7 +13,7 @@ def preprocess(action, add_options = {}) def execute(action) jt = job_template(action) - opts = get_job_options(action).deep_merge(:extra_vars => {'manageiq' => manageiq_extra_vars(action)}) + opts = get_job_options(action).deep_merge(:extra_vars => {'manageiq' => manageiq_extra_vars(action), 'manageiq_connection' => manageiq_connection_env}) hosts = opts.delete(:hosts) _log.info("Launching Ansible Tower job with options:") @@ -63,15 +63,32 @@ def on_error(action) def manageiq_extra_vars(action) { - 'api_url' => MiqRegion.my_region.remote_ws_url, - 'api_token' => Api::UserTokenService.new.generate_token(evm_owner.userid, 'api'), - 'service' => href_slug, - 'user' => evm_owner.href_slug, - 'group' => miq_group.href_slug, - 'action' => action + 'api_url' => api_url, + 'api_token' => api_token, + 'service' => href_slug, + 'user' => evm_owner.href_slug, + 'group' => miq_group.href_slug, + 'action' => action, + 'X_MIQ_Group' => evm_owner.current_group.description }.merge(request_options_extra_vars) end + def manageiq_connection_env + { + 'url' => api_url, + 'token' => api_token, + 'X_MIQ_Group' => evm_owner.current_group.description + } + end + + def api_token + @api_token ||= Api::UserTokenService.new.generate_token(evm_owner.userid, 'api') + end + + def api_url + @api_url ||= MiqRegion.my_region.remote_ws_url + end + def request_options_extra_vars miq_request_task.options.fetch_path(:request_options, :manageiq_extra_vars) || {} end diff --git a/spec/models/service_ansible_playbook_spec.rb b/spec/models/service_ansible_playbook_spec.rb index c3de9bbd498..46beda5fbf3 100644 --- a/spec/models/service_ansible_playbook_spec.rb +++ b/spec/models/service_ansible_playbook_spec.rb @@ -143,7 +143,7 @@ FactoryGirl.create(:miq_region, :region => ApplicationRecord.my_region_number) miq_request_task = FactoryGirl.create(:miq_request_task) miq_request_task.update_attributes(:options => {:request_options => {:manageiq_extra_vars => control_extras}}) - loaded_service.update_attributes(:evm_owner => FactoryGirl.create(:user), + loaded_service.update_attributes(:evm_owner => FactoryGirl.create(:user_with_group), :miq_group => FactoryGirl.create(:miq_group), :miq_request_task => miq_request_task) end @@ -151,8 +151,10 @@ it 'creates an Ansible Tower job' do expect(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Job).to receive(:create_job) do |jobtemp, opts| expect(jobtemp).to eq(tower_job_temp) - exposed_miq = %w(api_url api_token service user group) + control_extras.keys + exposed_miq = %w(api_url api_token service user group X_MIQ_Group) + control_extras.keys + exposed_connection = %w(url token X_MIQ_Group) expect(opts[:extra_vars].delete('manageiq').keys).to include(*exposed_miq) + expect(opts[:extra_vars].delete('manageiq_connection').keys).to include(*exposed_connection) expected_opts = provision_options[:provision_job_options].except(:hosts) expected_opts[:extra_vars]['pswd'] = decrpyted_val