vmware-archive / nsxansible

A set of example Ansible Modules using the above two projects as the basis
Other
109 stars 71 forks source link

vcenter_gather_moids.py enhancement for logical switch name #62

Closed virtualelephant closed 6 years ago

virtualelephant commented 6 years ago

Needed to be able to search for the MOID and distributed port group name after creating a new logical switch so that it can be used to create a new VM using the logical switch. Adding an else-if statement inside the def get_mo allowed me to accomplish this.

36 def get_mo(content, searchedname, vim_type_list): 37 mo = get_all_objs(content, vim_type_list) 38 for object in mo: 39 if object.name == searchedname: 40 return object 41 elif re.search( searchedname, object.name ): 42 return object 43 return None

88 object_id = object_mo._moId 89 object_name = object_mo.name 90 91 module.exit_json(changed=False, object_id=object_id, object_name=object_name, datacenter_moid=datacenter_moid)

Corresponding Ansible playbook code is: 21 - name: Gather MOID for NSX Logical Switch Portgroup 22 vcenter_gather_moids: 23 hostname: "{{ vcenter }}" 24 username: "{{ vcenter_user }}" 25 password: "{{ vcenter_pass }}" 26 datacenter_name: "{{ dc }}" 27 portgroup_name: "{{ switch_name }}" 28 validate_certs: False 29 register: gather_moids_pg