Azure Headache

Good morning all,

I’m very new to Ansible, but am looking to use it to baremetal and configure our company’s infrastructure products on either Azure or on client sites with VMware or Hyper-V. As the company is pushing Azure at the moment, I’m focusing on learning with that in the forefront of my mind. Whilst I’m able to fairly easily configure linux & windows machine running within our network, I am struggling with building environments within Azure, and somewhat falling at the first hurdle. I followed the bits in the guide https://docs.ansible.com/ansible/guide_azure.html and am using a service pricipal to connect to Azure. I installed the necessary modules via pip as follows:

sudo pip install “azure==2.0.0rc6”

sudo pip install msrestazure

sudo pip install enum

I am trying to get the very very basic playbook as follows to execute but barfs with the below syntax error within the module:

Hi stephen,

Getting the azure python modules just right are not for the faint of heart. I’m not sure which OS you’re running on, but:

First of all, this is not Ansible’s fault. Ansible uses the Azure python modules, which have a horrible story regarding versioning and dependencies and breaking changes. They are trying to clean this up, so hopefully it will improve.

The best way to ensure that your Azure things are working as they should is to fire up python on the computer where you’re running Ansible, and try and import the modules manually from there.
The module which actually imports the Azure stuff into ansible is here: https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/azure_rm_common.py. line 76-93 are the lines which do the import.
So, in order to test your setup, you can for example run (in your python shell):
from azure.mgmt.resource.resources.resource_management_client import ResourceManagementClient

Any import error you get there should be google-able, but please try it out and report back your results. We might have to get the documentation updated in case we forgot something. From the top of my head I think I had to update the “requests” module to get azure working a while back.

Good morning,

I’m running CentOS release 6.7 (Final) and Python 2.6. Thank you for your assistance so far, it appears the Syntax error is within the following module:

Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.

from azure.mgmt.resource.resources.resource_management_client import ResourceManagementClient
Traceback (most recent call last):
File “”, line 1, in
File “/usr/lib/python2.6/site-packages/azure/mgmt/resource/init.py”, line 1, in
from .features import FeatureClient
File “/usr/lib/python2.6/site-packages/azure/mgmt/resource/features/init.py”, line 22, in
from .feature_client import FeatureClient
File “/usr/lib/python2.6/site-packages/azure/mgmt/resource/features/feature_client.py”, line 125
client_models = {k: v for k, v in models.dict.items() if isinstance(v, type)}
^
SyntaxError: invalid syntax

Looks like I’ve managed to resolve this specific issue by running the rc5 version of the Azure modules under Python 2.7 :slight_smile: The connection to Azure is still failing, but with a sensible error now in that the details in my credentials file aren’t being passed to the module… but I can work with that. Thanks for your help :slight_smile: