Hi Kai,
Thank You so much for your help. The loop works with your suggestions except it seems to run a duplicate task and create a duplicate guest. This is with a test of 2 ESX hosts. Is there a way to work around it?
This is what I have in my inventory:
[esxi]
esxi1
esxi4
ansible-playbook --limit esxi cr_guests.yml
PLAY [all] *********************************************************************
TASK [setup] *******************************************************************
ok: [esxi4]
ok: [esxi1]
TASK [vsphere_guest] ***********************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: pysphere.resources.vi_exception.VIException: [Task Error]: Another task is already in progress.
failed: [esxi1] (item=({u’esx_host’: u’esxi1’}, u’vm1’)) => {“failed”: true, “item”: [{“esx_host”: “esxi1”}, “vm1”], “module_stderr”: “Traceback (most recent call last):\n File "/tmp/ansible_R7ozs3/ansible_module_vsphere_guest.py", line 1909, in \n main()\n File "/tmp/ansible_R7ozs3/ansible_module_vsphere_guest.py", line 1897, in main\n state=state\n File "/tmp/ansible_R7ozs3/ansible_module_vsphere_guest.py", line 1454, in create_vm\n vm.set_extra_config(vm_extra_config)\n File "/usr/lib/python2.7/site-packages/pysphere/vi_virtual_machine.py", line 1589, in set_extra_config\n FaultTypes.TASK_ERROR)\npysphere.resources.vi_exception.VIException: [Task Error]: Another task is already in progress.\n”, “module_stdout”: “”, “msg”: “MODULE FAILURE”}
changed: [esxi4] => (item=({u’esx_host’: u’esxi1’}, u’vm1’))
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: Value of unknown type: <class ‘pysphere.resources.vi_exception.VIException’>, [Task Error]: The attempted operation cannot be performed in the current state (Powered off).
failed: [esxi4] (item=({u’esx_host’: u’esxi4’}, u’vm3’)) => {“failed”: true, “item”: [{“esx_host”: “esxi4”}, “vm3”], “module_stderr”: “Traceback (most recent call last):\n File "/tmp/ansible_lt4K1b/ansible_module_vsphere_guest.py", line 1909, in \n main()\n File "/tmp/ansible_lt4K1b/ansible_module_vsphere_guest.py", line 1815, in main\n module.exit_json(changed=state_result)\n File "/tmp/ansible_lt4K1b/ansible_modlib.zip/ansible/module_utils/basic.py", line 1799, in exit_json\n File "/tmp/ansible_lt4K1b/ansible_modlib.zip/ansible/module_utils/basic.py", line 388, in remove_values\n File "/tmp/ansible_lt4K1b/ansible_modlib.zip/ansible/module_utils/basic.py", line 388, in \n File "/tmp/ansible_lt4K1b/ansible_modlib.zip/ansible/module_utils/basic.py", line 399, in remove_values\nTypeError: Value of unknown type: <class ‘pysphere.resources.vi_exception.VIException’>, [Task Error]: The attempted operation cannot be performed in the current state (Powered off).\n”, “module_stdout”: “”, “msg”: “MODULE FAILURE”}
changed: [esxi1] => (item=({u’esx_host’: u’esxi4’}, u’vm3’))
changed: [esxi4] => (item=({u’esx_host’: u’esxi4’}, u’vm4’))
changed: [esxi1] => (item=({u’esx_host’: u’esxi4’}, u’vm4’))
changed: [esxi1] => (item=({u’esx_host’: u’esxi4’}, u’vm5’))
changed: [esxi4] => (item=({u’esx_host’: u’esxi4’}, u’vm5’))
to retry, use: --limit @/root/learn/ansible/cr_guests.retry
PLAY RECAP *********************************************************************
esxi4 : ok=1 changed=0 unreachable=0 failed=1
esxi1 : ok=1 changed=0 unreachable=0 failed=1
Thanks,
Alex