diff --git a/app/models/manageiq/providers/embedded_ansible/automation_manager/playbook.rb b/app/models/manageiq/providers/embedded_ansible/automation_manager/playbook.rb index 2966f515175..c87a0f38216 100644 --- a/app/models/manageiq/providers/embedded_ansible/automation_manager/playbook.rb +++ b/app/models/manageiq/providers/embedded_ansible/automation_manager/playbook.rb @@ -41,7 +41,7 @@ def build_parameter_list(options) %i(credential vault_credential cloud_credential network_credential).each do |credential| cred_sym = "#{credential}_id".to_sym - params[credential] = Authentication.find(options[cred_sym]).manager_ref if options[cred_sym] + params[credential] = Authentication.find(options[cred_sym]).manager_ref if options[cred_sym].present? end params.compact diff --git a/spec/models/manageiq/providers/embedded_ansible/automation_manager/playbook_spec.rb b/spec/models/manageiq/providers/embedded_ansible/automation_manager/playbook_spec.rb index 33192a69123..4e362c8de9d 100644 --- a/spec/models/manageiq/providers/embedded_ansible/automation_manager/playbook_spec.rb +++ b/spec/models/manageiq/providers/embedded_ansible/automation_manager/playbook_spec.rb @@ -31,5 +31,21 @@ .to receive(:raw_create_in_provider).with(instance_of(manager.class), option_matcher) subject.raw_create_job_template(options) end + + it 'works with empty credential id' do + options = {:inventory => 'inv', :extra_vars => {'a' => 'x'}, :credential_id => ''} + option_matcher = hash_including( + :inventory => 'inv', + :extra_vars => '{"a":"x"}', + :playbook => subject.name, + :project => 'mref' + ) + + allow(subject).to receive(:configuration_script_source).and_return(double(:manager_ref => 'mref')) + expect(SecureRandom).to receive(:uuid).and_return('random-uuid') + expect(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ConfigurationScript) + .to receive(:raw_create_in_provider).with(instance_of(manager.class), option_matcher) + subject.raw_create_job_template(options) + end end end