[SOLVED] Get group information from group related to VM

Hi All!

We have on the group some tags with specific information what we’re using during the deployment but also during the retirement.
What I will doing is during the retirement off a vm getting the tags from the group that are related to the VM that will retired.

But how can I get the information from the group in the automation method? After some different tries I’m lost.



Assuming you are wanting to iterate the tags of the group who is the “owner” of the VM object you then could use something to the tune of:

  user = vm.owner
  $evm.log("info", "===== Owner: #{user.inspect}")

  group = vm.owner.current_group
  $evm.log("info", "===== Group: #{group.inspect}")

  miq_group = user.current_group

  unless miq_group.tags.nil?
    $evm.log("info","#{@method} - Group:<#{miq_group.description}> Begin Tags [miq_group.tags]")
    miq_group.tags.sort.each { |tag_element| tag_text = tag_element.split('/'); $evm.log("info", "#{@method} - Group:<#{miq_group.description}> Category:<#{tag_text.first.inspect}> Tag:<#{tag_text.last.inspect}>")}
    $evm.log("info","#{@method} - Group:<#{miq_group.description}> End Tags [miq_group.tags]")

if you instead wanted the current logged on user, then use the following:

user = $evm.root[‘user’]

at the very least this should get you primed on what info you need.

Adding pastebin in case the above is unreadable :smile:


Thanks for your reply and answer! The only problem is that we have users in multiple groups, they’re in LDAP groups. In our environment is a user group a project/tenant and on that groups are specific tags with configuration information applied.

When we want retire a service with an Admin useraccount we must use the group what is the owner off the service and not the group from the currrently logged on user. It can also not be the group from the service owner because he can logged in with another group.

@JSpaans91 Sounds like you need to put together a set of guidelines and requirements that will need to be followed through the whole lifecycle of the system. You then need to customize the options of the vm during provisioning to override the owner/group it will be belong to that will be used during retirement. Out of the box you have the options to do this by who requested it, and that does makes some assumptions for you that would require you to be logged in as the specified group in question. This means being logged in as yourself but with an admin or super admin group doing the tasks becomes troublesome down the line.

you will want to make sure things are set on the provisioning process following your specific business requirements. So if this is important for you, you will want to set the owner/group of WHO will be the ones that can show/perform the actual retirement. If you can’t even use the “logged” in user’s selected group you will need to try to figure a business process to alleviate this requirement. Basically what I am saying is you can make ManageIQ do whatever you want, but you have to configure a set of requirements throughout the lifecycle of the process (Provision and Retirement) to fit your guidelines.


Thanks for your feedback!
I choose for the option to set some specific custom keys on the VM with the information that is necessary.