ManageIQ - ansible tower Catalog bundle


#1

I followed this https://pemcg.gitbooks.io/mastering-automation-in-cloudforms-4-2-and-manage/content/creating_an_ansible_tower_service_catalog_item_and_bundle. Everything works fine except automatically fill the limit.

This piece of code:

def prior_service_vm_names
vm_names = []
unless task.provision_priority.zero?
prior_task = task.miq_request_task.miq_request_tasks.find do |miq_request_task|
miq_request_task.provision_priority == task.provision_priority - 1
end
unless prior_task.nil?
prior_task.miq_request_tasks.each do |child_task|
child_task.miq_request_tasks.each do |grandchild_task|
vm_names << grandchild_task.get_option(:vm_target_name)
end
end
end
end
vm_names
end

The code is executed till “unless prior_task.nil?” after that nothing. Can someone explain what is happening here:

unless prior_task.nil?
  prior_task.miq_request_tasks.each do |child_task|
    child_task.miq_request_tasks.each do |grandchild_task|
      vm_names << grandchild_task.get_option(:vm_target_name)
    end
  end

And how can I solve that limit is filled.

Kind regards,

Arjan


#2

@Arjan from ansible tower you should to set job template option “request limit at launch”. Otherwise the limit via the api will not work.


#3


#4

Hi igortiunov,

That option was already on, so that is not the problem.


#5

prior_task is the miq_request_task that was provisioned before the one that you’re running at the moment. Make sure the ‘Provision order’ is set correctly between your VM provisioning service and your Ansible service (see Figure 6. Bundle resources on that page). The Ansible service needs to be 1 higher than the VM provision service.

It’s also worth noting that some of the path and object names have changed with Fine/CFME 5.8. anything that was /ConfigurationManagement/AnsibleTower is now /AutomationManagement/AnsibleTower, and any of the service model objects that started ManageIQ_Providers_AnsibleTower_ConfigurationManager have been renamed to start ManageIQ_Providers_AnsibleTower_AutomationManager

Hope this helps,
pemcg


#6

Hi,

It is not working:

			  def prior_service_vm_names
                    @handle.log("info", "check 0")
					vm_names = []
					unless task.provision_priority.zero?
                        @handle.log("info", "Check 1")
						prior_task = task.miq_request_task.miq_request_tasks.find do |miq_request_task|
  						miq_request_task.provision_priority == task.provision_priority - 1
					end
                    @handle.log("info", "check 2")  
					unless prior_task.nil?
                        @handle.log("info", "check 3")
  						prior_task.miq_request_tasks.each do |child_task|
                          @handle.log("info", "check 4 #{child_task}")
    						child_task.miq_request_tasks.each do |grandchild_task|
                                @handle.log("info", "check 5 #{grandchild_task}")
      							vm_names << grandchild_task.get_option(:vm_target_name)
    						end
  						end
					end
				end
				vm_names
			  end

The code is executed till check 3, after that nothing… No errors… Can you help me what goes wrong. Provision order is correct. Creating the VM has priority 1 and action 1, the ansible service had priority 2 and action 2


#7

Which version of ManageIQ are you running?

Try the following in place of your “check 3” line as a debug statement:

prior_task.associations.each do |assoc|
  @handle.log("info", "Association: #{assoc}, length: #{assoc.length}")
end

#8

output:

[----] I, [2017-07-17T17:06:14.567822 #14306:55a25e4] INFO – : Q-task_id([service_template_provision_task_99000000000808]) Association: destination, length: 11
[----] I, [2017-07-17T17:06:14.569060 #14306:55a25e4] INFO – : Q-task_id([service_template_provision_task_99000000000808]) Association: miq_request, length: 11
[----] I, [2017-07-17T17:06:14.570186 #14306:55a25e4] INFO – : Q-task_id([service_template_provision_task_99000000000808]) Association: miq_request_task, length: 16
[----] I, [2017-07-17T17:06:14.571193 #14306:55a25e4] INFO – : Q-task_id([service_template_provision_task_99000000000808]) Association: miq_request_tasks, length: 17
[----] I, [2017-07-17T17:06:14.572270 #14306:55a25e4] INFO – : Q-task_id([service_template_provision_task_99000000000808]) Association: service_resource, length: 16
[----] I, [2017-07-17T17:06:14.573232 #14306:55a25e4] INFO – : Q-task_id([service_template_provision_task_99000000000808]) Association: source, length: 6
[----] I, [2017-07-17T17:06:14.578069 #14306:55a25e4] INFO – : Q-task_id([service_template_provision_task_99000000000808]) Association: tenant, length: 6


#9

Ha, yes, sorry my bad there, it’s printed the length of the assocation name.

Try this instead:

associations = Array.wrap(prior_task.associations)
unless associations.length.zero?
  associations.uniq.sort.each do |assoc|
    associated_objects = Array.wrap(prior_task.method_missing(:send, assoc))
    @handle.log("info", "Association: #{assoc}, length: #{associated_objects.length}")
  end
end

Which version of ManageIQ are you running? The original chapter was written for Euwe, I’ve never tested it on Fine


#10

we are running fine

This is the output:

3:57:54.260480 #2796:55146cc] INFO – : Q-task_id([service_template_provision_task_99000000000811]) check 3
[----] I, [2017-07-18T13:57:54.280920 #2796:55146cc] INFO – : Q-task_id([service_template_provision_task_99000000000811]) Association: destination, length: 1
[----] I, [2017-07-18T13:57:54.297081 #2796:55146cc] INFO – : Q-task_id([service_template_provision_task_99000000000811]) Association: miq_request, length: 1
[----] I, [2017-07-18T13:57:54.305785 #2796:55146cc] INFO – : Q-task_id([service_template_provision_task_99000000000811]) Association: miq_request_task, length: 1
[----] I, [2017-07-18T13:57:54.318019 #2796:55146cc] INFO – : Q-task_id([service_template_provision_task_99000000000811]) Association: miq_request_tasks, length: 0
[----] I, [2017-07-18T13:57:54.327010 #2796:55146cc] INFO – : Q-task_id([service_template_provision_task_99000000000811]) Association: service_resource, length: 1
[----] I, [2017-07-18T13:57:54.345786 #2796:55146cc] INFO – : Q-task_id([service_template_provision_task_99000000000811]) Association: source, length: 1
[----] I, [2017-07-18T13:57:54.362267 #2796:55146cc] INFO – : Q-task_id([service_template_provision_task_99000000000811]) Association: tenant, length: 1


#11

ok, thanks

Next question - did the VM provision complete successfully (no error)? What provider type was the VM provisioned into (i.e. VMware, RHV, Amazon etc)?

I’ll see if I can try this out on Fine


#12

The provider is Azure, the provision completed without errors. The only thing I want is the virtualMachineName in the job_options[:limit].

I have the object walker:

object_walker#B7C6E3A3:[6] destination.options[:create_options] = {:parameters=>{“adminUserName”=>“dec”, “adminPassword”=>“XXXXXXX”, “userImageName”=>“imageuserName”, “operatingSystemType”=>“linux”, “virtualMachineSize”=>“standard_d2_v2”, “virtualMachineName”=>“vmid1500377119”}, :resource_group=>“XXXXXX”, :mode=>“Incremental”} (type: Hash)


#13

I don’t think you’ll get an miq_request_task object if you provision a VM using an orchestration stack. The example used a ‘traditional’ VMProvision_VM state machine style of provisioning.

If you can access the property that you’re after from object_walker though, you should be able to pull this out in the same manner from your method.

Something like destination.get_option(:create_options)["virtualMachineName"] by the look of your snippet.


#14

Hi Peter,

There is no get_option method. Can you help me how I can extract virtualMachineName from destination.options?

This is the output of the object walker:

 |    |    |    |    destination = miq_request_task.destination
 |    |    |    |    (object type: MiqAeServiceServiceOrchestration, object ID: 99000000000827)
 |    |    |    |    |    --- attributes follow ---
 |    |    |    |    |    destination.ancestry = 99000000000826   (type: String)
 |    |    |    |    |    destination.created_at = 2017-07-19 19:23:24 UTC   (type: ActiveSupport::TimeWithZone)
 |    |    |    |    |    destination.description =    (type: String)
 |    |    |    |    |    destination.display = false   (type: FalseClass)
 |    |    |    |    |    destination.evm_owner_id = 99000000000001   (type: Fixnum)
 |    |    |    |    |    destination.guid = bc004654-6cb7-11e7-afba-000d3a273fcb   (type: String)
 |    |    |    |    |    destination.id = 99000000000827   (type: Fixnum)
 |    |    |    |    |    destination.initiator = user   (type: String)
 |    |    |    |    |    destination.miq_group_id = 99000000000002   (type: Fixnum)
 |    |    |    |    |    destination.name = Ubuntu on Azure-20170719-212536   (type: String)
 |    |    |    |    |    destination.options[:create_options] = {:parameters=>{"adminUserName"=>"dec", "adminPassword"=>"v2:{QsNG/mv5tSjpmq6hBkaJxCx0Bbz390T1wW9FuiMrwsA=}", "userImageName"=>"https://dectestsa.blob.core.windows.net/system/Microsoft.Compute/Images/templates/dec-ubuntu-blob-osDisk.071420c8-ced9-430f-8e8b-d2340afe0a7e.vhd ", "operatingSystemType"=>"linux", "virtualMachineSize"=>"standard_d2_v2", "ImageRefID"=>"/subscriptions/5190b643-3cce-43f2-8c93-3ceba92bb153/resourceGroups/dec-test-rg/providers/Microsoft.Compute/images/dec-test-ubuntu-image-20170504130025", "virtualMachineName"=>"vmid1500492349", "departmentTag"=>"bco", "experimentTag"=>"test_2", "roleTag"=>"roldb", "emailTag"=>"admin"}, :resource_group=>"test_2", :mode=>"Incremental"}   (type: Hash)
 |    |    |    |    |    destination.options[:dialog] = {"dialog_deploy_mode"=>"Incremental", "dialog_limit"=>"changeme", "dialog_vm_name"=>"changeme", "dialog_param_adminUserName"=>"dec", "password::param_adminPassword"=>"v2:{QsNG/mv5tSjpmq6hBkaJxCx0Bbz390T1wW9FuiMrwsA=}", "password::dialog_param_adminPassword"=>"v2:{QsNG/mv5tSjpmq6hBkaJxCx0Bbz390T1wW9FuiMrwsA=}", "dialog_param_userImageName"=>"https://dectestsa.blob.core.windows.net/system/Microsoft.Compute/Images/templates/dec-ubuntu-blob-osDisk.071420c8-ced9-430f-8e8b-d2340afe0a7e.vhd ", "dialog_param_operatingSystemType"=>"linux", "dialog_param_virtualMachineSize"=>"standard_d2_v2", "dialog_param_ImageRefID"=>"/subscriptions/5190b643-3cce-43f2-8c93-3ceba92bb153/resourceGroups/dec-test-rg/providers/Microsoft.Compute/images/dec-test-ubuntu-image-20170504130025", "dialog_service_retires_on"=>"2017-07-31T19:22:00Z"}   (type: Hash)
 |    |    |    |    |    destination.options[:orchestration_stack] = {"name"=>"Stackbcotest_arjan_2roldb1500492349", "type"=>"ManageIQ::Providers::Azure::CloudManager::OrchestrationStack", "status"=>"CREATE_IN_PROGRESS", "ems_ref"=>"/subscriptions/5190b643-3cce-43f2-8c93-3ceba92bb153/resourceGroups/test_arjan_2/providers/Microsoft.Resources/deployments/Stackbcotest_arjan_2roldb1500492349", "ems_id"=>99000000000001, "orchestration_template_id"=>99000000000072, "created_at"=>Wed, 19 Jul 2017 19:26:30 UTC +00:00, "updated_at"=>Wed, 19 Jul 2017 19:26:30 UTC +00:00, "resource_group"=>"test_arjan_2"}   (type: Hash)
 |    |    |    |    |    destination.options[:power_status] = start_complete   (type: String)
 |    |    |    |    |    destination.retired = false   (type: FalseClass)
 |    |    |    |    |    destination.retirement_last_warn = nil
 |    |    |    |    |    destination.retirement_requester = nil
 |    |    |    |    |    destination.retirement_state = nil
 |    |    |    |    |    destination.retirement_warn = 2   (type: Fixnum)
 |    |    |    |    |    destination.retires_on = 2017-07-31 19:22:00 UTC   (type: ActiveSupport::TimeWithZone)
 |    |    |    |    |    destination.service_template_id = 99000000000046   (type: Fixnum)
 |    |    |    |    |    destination.tenant_id = 99000000000001   (type: Fixnum)
 |    |    |    |    |    destination.type = ServiceOrchestration   (type: String)
 |    |    |    |    |    destination.updated_at = 2017-07-19 19:43:47 UTC   (type: ActiveSupport::TimeWithZone)
 |    |    |    |    |    --- end of attributes ---
 |    |    |    |    |    --- virtual columns follow ---
 |    |    |    |    |    destination.aggregate_all_vm_cpus = 2   (type: Fixnum)
 |    |    |    |    |    destination.aggregate_all_vm_disk_count = 1   (type: Fixnum)
 |    |    |    |    |    destination.aggregate_all_vm_disk_space_allocated = 1072693248   (type: Fixnum)
 |    |    |    |    |    destination.aggregate_all_vm_disk_space_used = 1072693248   (type: Fixnum)
 |    |    |    |    |    destination.aggregate_all_vm_memory = 7168   (type: Fixnum)
 |    |    |    |    |    destination.aggregate_all_vm_memory_on_disk = 7516192768   (type: Fixnum)
 |    |    |    |    |    destination.aggregate_direct_vm_cpus = 2   (type: Fixnum)
 |    |    |    |    |    destination.aggregate_direct_vm_disk_count = 1   (type: Fixnum)
 |    |    |    |    |    destination.aggregate_direct_vm_disk_space_allocated = 1072693248   (type: Fixnum)
 |    |    |    |    |    destination.aggregate_direct_vm_disk_space_used = 1072693248   (type: Fixnum)
 |    |    |    |    |    destination.aggregate_direct_vm_memory = 7168   (type: Fixnum)
 |    |    |    |    |    destination.aggregate_direct_vm_memory_on_disk = 7516192768   (type: Fixnum)
 |    |    |    |    |    destination.custom_1 = nil
 |    |    |    |    |    destination.custom_2 = nil
 |    |    |    |    |    destination.custom_3 = nil
 |    |    |    |    |    destination.custom_4 = nil
 |    |    |    |    |    destination.custom_5 = nil
 |    |    |    |    |    destination.custom_6 = nil
 |    |    |    |    |    destination.custom_7 = nil
 |    |    |    |    |    destination.custom_8 = nil
 |    |    |    |    |    destination.custom_9 = nil
 |    |    |    |    |    destination.evm_owner_email = a@a.nl   (type: String)
 |    |    |    |    |    destination.evm_owner_name = admin   (type: String)
 |    |    |    |    |    destination.evm_owner_userid = admin   (type: String)
 |    |    |    |    |    destination.has_parent = true   (type: TrueClass)
 |    |    |    |    |    destination.href_slug = services/99000000000827   (type: String)
 |    |    |    |    |    destination.owned_by_current_ldap_group = nil
 |    |    |    |    |    destination.owned_by_current_user = nil
 |    |    |    |    |    destination.owning_ldap_group = EvmGroup-super_administrator   (type: String)
 |    |    |    |    |    destination.power_state = on   (type: String)
 |    |    |    |    |    destination.power_status = start_complete   (type: String)
 |    |    |    |    |    destination.region_description = Region 99   (type: String)
 |    |    |    |    |    destination.region_number = 99   (type: Fixnum)
 |    |    |    |    |    destination.service_id = 99000000000826   (type: Fixnum)
 |    |    |    |    |    destination.v_total_vms = 1   (type: Fixnum)
 |    |    |    |    |    --- end of virtual columns ---
 |    |    |    |    |    --- associations follow ---
 |    |    |    |    |    destination.all_service_children (type: Association (empty))
 |    |    |    |    |    destination.direct_service_children (type: Association (empty))
 |    |    |    |    |    destination.direct_vms (type: Association)
 |    |    |    |    |    *** not walking: 'direct_vms' isn't in the walk_association_whitelist hash for MiqAeServiceServiceOrchestration ***
 |    |    |    |    |    destination.indirect_service_children (type: Association (empty))
 |    |    |    |    |    destination.indirect_vms (type: Association (empty))
 |    |    |    |    |    destination.parent_service (type: Association)
 |    |    |    |    |    *** not walking: 'parent_service' isn't in the walk_association_whitelist hash for MiqAeServiceServiceOrchestration ***
 |    |    |    |    |    destination.root_service (type: Association)
 |    |    |    |    |    *** not walking: 'root_service' isn't in the walk_association_whitelist hash for MiqAeServiceServiceOrchestration ***
 |    |    |    |    |    destination.service_resources (type: Association)
 |    |    |    |    |    *** not walking: 'service_resources' isn't in the walk_association_whitelist hash for MiqAeServiceServiceOrchestration ***
 |    |    |    |    |    destination.service_template (type: Association)
 |    |    |    |    |    *** not walking: 'service_template' isn't in the walk_association_whitelist hash for MiqAeServiceServiceOrchestration ***
 |    |    |    |    |    destination.tenant (type: Association)
 |    |    |    |    |    *** not walking: 'tenant' isn't in the walk_association_whitelist hash for MiqAeServiceServiceOrchestration ***
 |    |    |    |    |    destination.vms (type: Association)
 |    |    |    |    |    *** not walking: 'vms' isn't in the walk_association_whitelist hash for MiqAeServiceServiceOrchestration ***
 |    |    |    |    |    --- end of associations ---
 |    |    |    |    |    --- methods follow ---
 |    |    |    |    |    destination.automate_retirement_entrypoint
 |    |    |    |    |    destination.build_stack_options_from_dialog
 |    |    |    |    |    destination.custom_get
 |    |    |    |    |    destination.custom_keys
 |    |    |    |    |    destination.custom_set
 |    |    |    |    |    destination.deploy_orchestration_stack
 |    |    |    |    |    destination.description=
 |    |    |    |    |    destination.dialog_options
 |    |    |    |    |    destination.display=
 |    |    |    |    |    destination.error_retiring?
 |    |    |    |    |    destination.extend_retires_on
 |    |    |    |    |    destination.finish_retirement
 |    |    |    |    |    destination.get_dialog_option
 |    |    |    |    |    destination.group=
 |    |    |    |    |    destination.inspect
 |    |    |    |    |    destination.inspect_all
 |    |    |    |    |    destination.model_suffix
 |    |    |    |    |    destination.name=
 |    |    |    |    |    destination.orchestration_manager
 |    |    |    |    |    destination.orchestration_manager=
 |    |    |    |    |    destination.orchestration_stack
 |    |    |    |    |    destination.orchestration_stack_status
 |    |    |    |    |    destination.orchestration_template
 |    |    |    |    |    destination.orchestration_template=
 |    |    |    |    |    destination.owner=
 |    |    |    |    |    destination.parent_service=
 |    |    |    |    |    destination.post_provision_configure
 |    |    |    |    |    destination.reload
 |    |    |    |    |    destination.remove_from_vmdb
 |    |    |    |    |    destination.retire_now
 |    |    |    |    |    destination.retire_service_resources
 |    |    |    |    |    destination.retired?
 |    |    |    |    |    destination.retirement_state=
 |    |    |    |    |    destination.retirement_warn=
 |    |    |    |    |    destination.retires_on=
 |    |    |    |    |    destination.retiring?
 |    |    |    |    |    destination.set_dialog_option
 |    |    |    |    |    destination.shutdown_guest
 |    |    |    |    |    destination.stack_name
 |    |    |    |    |    destination.stack_name=
 |    |    |    |    |    destination.stack_options
 |    |    |    |    |    destination.stack_options=
 |    |    |    |    |    destination.start
 |    |    |    |    |    destination.start_retirement
 |    |    |    |    |    destination.stop
 |    |    |    |    |    destination.suspend
 |    |    |    |    |    destination.tag_assign
 |    |    |    |    |    destination.tag_unassign
 |    |    |    |    |    destination.tagged_with?
 |    |    |    |    |    destination.tags
 |    |    |    |    |    destination.update_options
 |    |    |    |    |    destination.update_options=
 |    |    |    |    |    destination.update_orchestration_stack
 |    |    |    |    |    --- end of methods ---
 |    |    |    |    |    --- tags follow ---
 |    |    |    |    |    gemeente_department/bco
 |    |    |    |    |    gemeente_experiment/test_arjan_2
 |    |    |    |    |    gemeente_role/roldb
 |    |    |    |    |    --- end of tags ---
 |    |    |    |    |    --- no custom attributes ---

Arjan


#15

@pemcg Can you please help me?


#16

It looks like it might be:

destination.options[:create_options][:parameters][“virtualMachineName”]


#17

@pemcg, I added the code but I got an error:

[----] E, [2017-07-26T10:20:29.435360 #58195:48ea810] ERROR – : Q-task_id([service_template_provision_task_99000000000857]) The following error occurred during method evaluation:
[----] E, [2017-07-26T10:20:29.438508 #58195:48ea810] ERROR – : Q-task_id([service_template_provision_task_99000000000857]) NoMethodError: undefined method []' for nil:NilClass [----] E, [2017-07-26T10:20:29.440808 #58195:48ea810] ERROR -- : Q-task_id([service_template_provision_task_99000000000857]) <AutomationEngine> <AEMethod preprovision_from_bundle> /Rotterdam_provisioning_27-06_2017/AutomationManagement/AnsibleTower/Service/Provisioning/StateMachines/Provision/preprovision_from_bundle:77:inmodify_job_options’


#18

Hi @Arjan @pemcg

Did you manage to get this working? I am having the same issue. Now that I am using a CatalogBundleInit the code for fetching dialog option/elements aren’t working.

This used to work (and works via CatalogItemInit for a non bubdle request)
app = task.get_option(:dialog)[‘dialog_job_template_name’]

I have tried app = task.get_option(:dialog)[‘dialog_job_template_name’] || task.destination.get_dialog_option(:dialog)[‘dialog_job_template_name’]

and a few other variants eg
|| task.destination.get_option(:dialog)[‘dialog_job_template_name’]
|| task.destination.options(:dialog)[‘dialog_job_template_name’]

But nothing works so far…

I can see from objwalker its there…

 |    |    $evm.root['service_template_provision_task'].destination (type: Association)
 |    |    destination = $evm.root['service_template_provision_task'].destination
 |    |    (object type: MiqAeServiceService, object ID: 51000000001364)

destination.options[:dialog] = {“dialog_itsm_env”=>“DR”, “dialog_zone”=>“B2c”, “dialog_baas”=>“No”, “dialog_monitor”=>“No”, “dialog_envname”=>“Non-Prod”, “dialog_cx_project_id”=>“imt12345”, “dialog_cx_remedy_appid”=>“0000”, “dialog_cx_crq_id”=>“abcd123456”, “dialog_vm_size”=>“Small”, “dialog_user_number_of_vms”=>“1”, “dialog_number_of_vms”=>“1”, “dialog_job_template_name”=>“IHS.Web.IH”} (type: Hash)

Thanks


#19

I’d have thought it would be:

task.destination.options[:dialog]['dialog_job_template_name']

The get_option method is only available on a request or task object.

Cheers,
pemcg


#20

hey @pemcg, that has fixed. Thanks :+1::fist_right: