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 42538cdbcf4..12c33ffbc6a 100644 --- a/app/models/manageiq/providers/embedded_ansible/automation_manager/playbook.rb +++ b/app/models/manageiq/providers/embedded_ansible/automation_manager/playbook.rb @@ -15,15 +15,17 @@ def run(options, userid = nil) # return provider raw object def raw_create_job_template(options) job_template_klass = ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ConfigurationScript - job_template_klass.raw_create_in_provider(manager, build_parameter_list(options)) + jt_options = build_parameter_list(options) + _log.info("Creating job template with options (#{jt_options})") + job_template_klass.raw_create_in_provider(manager, jt_options) end private def build_parameter_list(options) params = { - :name => options[:template_name] || "#{name}_#{Time.zone.now.to_i}", - :description => options[:description] || '', + :name => options[:template_name] || "#{name}_#{SecureRandom.uuid}", + :description => options[:description] || "Created on #{Time.zone.now}", :project => configuration_script_source.manager_ref, :playbook => name, :become_enabled => options[:become_enabled].present?, diff --git a/app/models/manageiq/providers/embedded_ansible/automation_manager/playbook_runner.rb b/app/models/manageiq/providers/embedded_ansible/automation_manager/playbook_runner.rb index 5f55d5f2a57..36b3c5c3c78 100644 --- a/app/models/manageiq/providers/embedded_ansible/automation_manager/playbook_runner.rb +++ b/app/models/manageiq/providers/embedded_ansible/automation_manager/playbook_runner.rb @@ -23,7 +23,9 @@ def start def create_inventory set_status('creating inventory') - inventory_name = "#{playbook.name}_#{Time.zone.now.to_i}" + inventory_name = "#{playbook.name}_#{SecureRandom.uuid}" + + _log.info("Creating inventory #{inventory_name} including hosts (#{options[:hosts]})") options[:inventory] = ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Inventory .raw_create_inventory(playbook.manager, inventory_name, options[:hosts]).id save! @@ -162,7 +164,7 @@ def temp_configuration_script end def delete_inventory - return unless options[:inventory] + return true unless options[:inventory] playbook.manager.with_provider_connection do |connection| connection.api.inventories.find(options[:inventory]).destroy! end @@ -173,6 +175,7 @@ def delete_inventory end def delete_job_template + return true unless options[:job_template_ref] temp_configuration_script.raw_delete_in_provider rescue => err # log the error but do not treat the playbook running as failure diff --git a/spec/models/manageiq/providers/embedded_ansible/automation_manager/playbook_runner_spec.rb b/spec/models/manageiq/providers/embedded_ansible/automation_manager/playbook_runner_spec.rb index 4e96173b57f..91485311334 100644 --- a/spec/models/manageiq/providers/embedded_ansible/automation_manager/playbook_runner_spec.rb +++ b/spec/models/manageiq/providers/embedded_ansible/automation_manager/playbook_runner_spec.rb @@ -40,6 +40,7 @@ it 'creates an inventory and moves on to create_job_template' do # Also test signal with queue subject.send(:minimize_indirect=, false) + expect(SecureRandom).to receive(:uuid).and_return('random-uuid') expect(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Inventory).to receive(:raw_create_inventory).and_return(double(:id => 'inv1')) expect(subject).to receive(:queue_signal).with(:create_job_template, :deliver_on => nil) subject.create_inventory 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 e4a6e709376..00b140ce16d 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 @@ -22,6 +22,7 @@ ) 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)