3
votes

I am trying to get Ansible to deploy resources to the Azure cloud and I am having an error while getting it in to work. I have a fresh install of Ubuntu 14.04

I have installed ansible by running the following:

 - sudo apt-get install software-properties-common
 - sudo apt-add-repository ppa:ansible/ansible
 - sudo apt-get update
 - sudo apt-get install ansible

I also installed pip by running the command

 - sudo easy_install pip

And that all was done to get ansible install on the server. Then I started with the Azure components for Ansible by following the instructions given here.

I ran the command sudo pip install "azure==2.0.0rc5" to get the Azure Python SDK. Then I created a simple yaml file to create a resource group and when I ran the playbook by running the command ansible-playbook test.yml -vvv the following error was returned:

fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_args": {"ad_user": null, "append_tags": true, "client_id": null, "force": false, "location": null, "name": "test", "password": null, "profile": null, "secret": null, "state": "present", "subscription_id": null, "tags": null, "tenant": null}, "module_name": "azure_rm_resourcegroup"}, "msg": "Do you have azure==2.0.0rc5 installed? Try pip install azure==2.0.0rc5- No module named enum"}

2

2 Answers

0
votes

Ansible suggestion in this error message is really confusing. Usually you need to add a few more packages besides azure==2.0.0rc5.

Pay attention to the package name given in the following part of the message:

No module named enum

So in this case try:

sudo pip install enum

One thing to check is: Ubuntu 16.04, Python 2.7 - ImportError: No module named enum I'm not sure if it applies in this situation, it looks like 16.04 problem. I did have enum installed by default.

From my experience you'll also need:

sudo pip install msrest
sudo pip install msrestazure
5
votes

New answer for Ansible 3.0+ / ansible-core 2.10+:

To install Azure support, use the Ansible Azure collection as follows:

# Install dependencies
curl -O https://raw.githubusercontent.com/ansible-collections/azure/dev/requirements-azure.txt
pip install -r requirements-azure.txt

# Install collection
ansible-galaxy collection install azure.azcollection
  • requirements-azure.txt specifies versions for all libraries, so it's best to reinstall these if you upgrade the collection version
  • consider checking this in to 'pin' versions of dependencies
  • you may want to pin the collection version as well

As an Ansible collection, this Ansible Azure support can now be more rapidly updated outside the Ansible core release process.

Updated for ansible-core 2.10+, which is included in Ansible 3.0 and higher.


Original answer worked up to Ansible 2.9:

The simplest and most reliable way to install the Azure packages for Ansible is:

pip install ansible[azure]==2.8.6

This installs the Azure dependencies required for this Ansible version. If you want to use the latest version, omit the ==2.8.6 part.

This works because the Ansible project defines the exact dependency versions (as of 2.9.9) that it needs for Azure support as an 'extra' in its Python packaging setup.