[Solved] Automatically Setting the Ansible 'limit' variable in a Service Bundle


#1

I’m trying to follow Peter’s method of setting the Ansible limit variable within a service bundle: https://pemcg.gitbooks.io/mastering-automation-in-cloudforms-4-2-and-manage/content/creating_an_ansible_tower_service_catalog_item_and_bundle/chapter.html#i7

I have a VM provision service and an Ansible Tower (Nagios Setup) service in the bundle.
I am investigating the objects within Rails console after the bundle provision, and having some odd results:

irb(main):076:0> req = $evm.vmdb(:miq_request).where(:id => 161).first 
=> #<MiqAeServiceServiceTemplateProvisionRequest:0x4466514 @object=#<ServiceTemplateProvisionRequest id: 161, description: "Provisioning Service [Linux VM Bundle] from [Linux...", approval_state: "approved", type: "ServiceTemplateProvisionRequest", created_on: "2018-02-08 15:16:56", updated_on: "2018-02-08 15:26:09", fulfilled_on: "2018-02-08 15:26:09", requester_id: 1, requester_name: "Administrator", request_type: "clone_to_service", request_state: "finished", message: "[EVM] Service [Linux VM Bundle-20180208-161742] Pr...", status: "Ok", options: {:dialog=>{"dialog_option_1_service_name"=>"", "dialog_option_1_service_description"=>"", "dialog_tag_0_environment"=>"dev", "Array::dialog_tag_0_monitoring_timeperiod"=>"Classification::143", "dialog_tag_1_role"=>"app", "dialog_option_1_vm_name"=>"", "dialog_option_1_flavor"=>"medium", "dialog_option_1_vlan_id"=>"10", "dialog_option_2_param_monitoring_hostgroups"=>"webservers"}, :workflow_settings=>{:resource_action_id=>1500, :dialog_id=>12}, :initiator=>nil, :src_id=>8, :cart_state=>"ordered", :requester_group=>"EvmGroup-super_administrator", :delivered_on=>2018-02-08 15:17:15 UTC, :user_message=>"[EVM] Service [Linux VM Bundle-20180208-161742] Provisioned Successfully"}, userid: "admin", source_id: 8, source_type: "ServiceTemplate", destination_id: nil, destination_type: nil, tenant_id: 1, service_order_id: 109, process: true>, @virtual_columns=["href_slug", "reason", "region_description", "region_number", "request_type_display", "resource_type", "stamped_on", "state", "v_allowed_tags", "v_approved_by", "v_approved_by_email", "v_workflow_class"], @associations=["approvers", "destination", "miq_request", "miq_request_tasks", "requester", "resource", "source", "tenant"]> 

irb(main):082:0> req.miq_request_tasks.each { |t| puts t.description ; puts t.provision_priority rescue nil};nil 
Provisioning [Linux VM Bundle] for Service [Linux VM Bundle] 
0 
Provision from [CentOS.7.x64_template] to [cfmedevapp003] 
Provisioning [Linux VM] for Service [Linux VM] 
0 
Provisioning [Nagios Setup] for Service [Nagios Setup] 
1 
Provisioning VM [CentOS.7.x64_template] for Service [CentOS.7.x64_template] 
0 
=> nil 

According to the book figure the Ansible Tower task (Nagios Setup) should have 1 for provision_priority and the VM provision task one less (0) and we find the VM prov task based on this priority value. But I have more than one tasks with 0 priority. Can you explain why?


#2

My bad: I was looking at the prov request and not the task:

irb(main):085:0> reqt = $evm.vmdb(:miq_request_task).where(:id => 321).first 
=> #<MiqAeServiceServiceTemplateProvisionTask:0x3a1095c @object=#<ServiceTemplateProvisionTask id: 321, description: "Provisioning [Linux VM Bundle] for Service [Linux ...", state: "finished", request_type: "clone_to_service", userid: "admin", options: {:dialog=>{"dialog_option_1_service_name"=>"", "dialog_option_1_service_description"=>"", "dialog_tag_0_environment"=>"dev", "Array::dialog_tag_0_monitoring_timeperiod"=>"Classification::143", "dialog_tag_1_role"=>"app", "dialog_option_1_vm_name"=>"", "dialog_option_1_flavor"=>"medium", "dialog_option_1_vlan_id"=>"10", "dialog_option_2_param_monitoring_hostgroups"=>"webservers", "request"=>"clone_to_service", :service_action=>"Provision", "Service::Service"=>120}, :workflow_settings=>{:resource_action_id=>1500, :dialog_id=>12}, :initiator=>nil, :src_id=>8, :cart_state=>"ordered", :requester_group=>"EvmGroup-super_administrator", :delivered_on=>2018-02-08 15:17:15 UTC, :pass=>0, :parsed_dialog_options=>"---\n1:\n  :flavor: medium\n  :vlan_id: '10'\n2:\n  :param_monitoring_hostgroups: webservers\n", :parsed_dialog_tags=>"---\n0:\n  :environment: dev\n  :monitoring_timeperiod:\n  - workhours\n1:\n  :role: app\n"}, created_on: "2018-02-08 15:17:16", updated_on: "2018-02-08 15:26:08", message: "Task complete", status: "Ok", type: "ServiceTemplateProvisionTask", miq_request_id: 161, source_id: 8, source_type: "ServiceTemplate", destination_id: 120, destination_type: "Service", miq_request_task_id: nil, phase: nil, phase_context: {}, tenant_id: 1>, @virtual_columns=["href_slug", "region_description", "region_number"], @associations=["destination", "miq_request", "miq_request_task", "miq_request_tasks", "service_resource", "source", "tenant"]> 
 
irb(main):088:0> reqt.miq_request_tasks.each { |t| puts t.description ; puts t.provision_priority};nil 
Provisioning [Nagios Setup] for Service [Nagios Setup] 
1 
Provisioning [Linux VM] for Service [Linux VM] 
0 
=> nil