Cloud Shell cannot build Azure infrastructure via Ansible

rzand 6 Reputation points

Cannot build Azure infrastructure via ansible from the cloud shell environment. Keep getting

Failed to import the required Python library (ansible[azure] (azure >= 2.0.0))

I tested on different tenant and used a non MFA user.

From my WSL shell I can create infrastructure if I use a root account, is this the issue?

Cannot find up-to-date documentation about this.


Not Monitored
Not Monitored
Tag not monitored by Microsoft.
37,169 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. William 615 Reputation points

    It seems like you’re encountering an issue while trying to build Azure infrastructure using Ansible from the Azure Cloud Shell. Let's troubleshoot this together.

    Automatic Credential Configuration:

    • When you’re signed into the Azure Cloud Shell, Ansible should authenticate with Azure to manage infrastructure without any extra configuration1.
      • Make sure you’re using the correct Azure subscription. If you’re working with multiple subscriptions, you can specify the subscription Ansible should use by exporting the AZURE_SUBSCRIPTION_ID environment variable. To list all your Azure subscriptions, run the following command:
            az account list
      - Then set the **`AZURE_SUBSCRIPTION_ID`** using your Azure subscription ID:
      export AZURE_SUBSCRIPTION_ID=<your-subscription-id>
      **Python Library Dependencies**:
         - The error message indicates that Ansible is missing the required Python library **`ansible[azure]`**. Ensure that you have Ansible installed with the necessary Azure modules. You can install it using pip:
         pip install ansible[azure]
         **WSL vs. Cloud Shell**:
            - You mentioned that you can create infrastructure from your WSL shell using a root account. This suggests that the issue might be specific to the Azure Cloud Shell environment.
               - Check if there are any differences in the Python environment or permissions between WSL and Cloud Shell. For example, ensure that the necessary Python packages are available in Cloud Shell.

    Documentation and Troubleshooting:

    • While it’s true that up-to-date documentation is essential, sometimes finding the right information can be challenging. Here are some resources you can explore:
    • Configure Ansible using Azure Cloud Shell: This Microsoft Learn article provides step-by-step instructions for setting up Ansible in Azure Cloud Shell.
    • Microsoft Azure Guide: The official Ansible documentation includes guidance on using Ansible with Azure.
    - [Automating Infrastructure Deployments in the Cloud with Ansible and Azure]( This lab covers deploying Azure resources using Ansible.
    0 comments No comments

  2. rzand 6 Reputation points

    The answer does not solve the problem nor answer the original question of the need to run the command as a root user.