ansible/ansible — pull request #8094 by ghjm (2014-07-11 03:14:25+00:00)
Title: Fixed tracebacks during VM creation. Fixes #8067.

This patch fixes three tracebacks that can occur when creating a vSphere virtual machine:

1. If the datacenter name in the playbook does not exist on the vCenter server, the list comprehension gives an empty result and dereferencing to [0] fails. Instead of checking if [0]==None, we check if the list has any members. If it does, then we can use [0].

2. If the playbook does not supply a value for the notes parameter in vm_extra_config, this causes a traceback when we try to compare it to None. Instead, we should check if the "notes" key is present in the dictionary. If it is present and also has the value None, then we wind up setting the annotation to None, which seems like reasonable behavior.

3. If vm_extra_config is not supplied and the power state is not requested to be on or off, then we are not retrieving the vm from pysphere, which causes a traceback when we try to gather facts about it at the end of the module. Since we always want to gather these facts, we always need the vm reference.