ansible/ansible-modules-core — pull request #540 by lander2k2 (2014-12-17 22:36:30+00:00)
Title: azure check for hosted service and vm before creating

Order of operations with Azure:
1. create cloud/hosted service
2. provision virtual machine in the cloud service

Currently:
1. does cloud service exist?
Yes: fail (see error below)
No: create service and then go to step 2
2. provision virtual machine (fails if vm already exists)

Error if a cloud service already exists:

TASK: [azure] *****************************************************************
failed: [localhost -> 127.0.0.1] => {"failed": true}
msg: failed to lookup the deployment information for [vm name], error was: Not found (Not Found)

FATAL: all hosts have already failed -- aborting

Error if a virtual machine already exists:

TASK: [azure] *****************************************************************
failed: [localhost -> 127.0.0.1] => {"failed": true}
msg: failed to create the new virtual machine, error was: Conflict (Conflict)

FATAL: all hosts have already failed -- aborting

This patch does the following:
1. Does cloud service exist?
Yes: got to step 2
No: create service and then go to step 2

2. Does vm exist?
Yes: return changed=False
No: create vm