You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure DevOps流水线运行Ansible playbook遇模块缺失错误

Ansible Azure模块依赖缺失问题排查

问题描述

已确认安装Ansible Azure模块所需全部依赖,但在Azure DevOps流水线中运行调用azure_rm_resourcegroup模块的playbook时,出现以下错误:

完整回溯信息:
Traceback (most recent call last):
  File "/tmp/ansible_azure_rm_resourcegroup_payload_7l31ymh4/ansible_azure_rm_resourcegroup_payload.zip/ansible_collections/azure/azcollection/plugins/module_utils/azure_rm_common.py", line 250, in <module>
    from azure.storage.cloudstorageaccount import CloudStorageAccount
ModuleNotFoundError: No module named 'azure.storage.cloudstorageaccount'

Azure DevOps流水线配置

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: UsePythonVersion@0
  displayName: 'Install Python'
  inputs:
    versionSpec: '3.x'
    addToPath: true
    architecture: 'x64'

- task: AzureCLI@2
  inputs:
    azureSubscription: '$(AZURE_SUBSCRIPTION_NAME)'
    addSpnToEnvironment: true
    scriptType: 'bash'
    scriptLocation: 'inlineScript'
    inlineScript: |
      echo "##vso[task.setvariable variable=ARM_SUBSCRIPTION_ID]$(az account show --query='id' -o tsv)"
      echo "##vso[task.setvariable variable=ARM_CLIENT_ID]${servicePrincipalId}"
      echo "##vso[task.setvariable variable=ARM_CLIENT_SECRET]${servicePrincipalKey}"
      echo "##vso[task.setvariable variable=ARM_TENANT_ID]${tenantId}"

- script: pip install ansible[azure]
  displayName: 'Install Ansible'

- script: ansible-galaxy collection install azure.azcollection
  displayName: 'Install Ansible Azure Collection' 

- script: pip install -r https://raw.githubusercontent.com/ansible-collections/azure/dev/requirements-azure.txt
  displayName: 'Install Azure modules needed'

- script: pip install azure-storage-blob azure-storage-file-share azure-storage-file-datalake azure-storage-queue
  displayName: 'Install missing modules (to be sure to have the azure storage modules)'

- script: ansible-playbook -vvv -i inv site.yml
  displayName: 'Run Ansible Playbook'
  env:
    AZURE_CLIENT_ID: $(ARM_CLIENT_ID)
    AZURE_SECRET: $(ARM_CLIENT_SECRET)
    AZURE_TENANT: $(ARM_TENANT_ID)
    AZURE_SUBSCRIPTION_ID: $(ARM_SUBSCRIPTION_ID)

Playbook内容

---

- name: config azure environment
  hosts: localhost
  connection: local
  gather_facts: true
  collections:
    - azure.azcollection

  vars_files:
    - group_vars/common.yml

  roles:
    - roles/resourcegroup

对应Role内容

---

- name: create a resource group
  azure_rm_resourcegroup:
    name: "{{ app.name }}-{{ dict.resource_group }}"
    location: "{{ azure.location }}"
    state: present

按照官方文档配置仍未解决,请问遗漏了什么?

解决方案

问题核心是azure.storage.cloudstorageaccount属于旧版Azure Storage SDK(对应azure-storage包),而你安装的是新版拆分后的存储包(如azure-storage-blob),两者不兼容。Ansible Azure集合的部分模块尚未完全适配新版SDK,需补充安装旧版包:

  • 在流水线中新增安装旧版Azure Storage包的步骤:

    pip install azure-storage==0.36.0
    
  • 调整依赖安装顺序,避免版本冲突:
    修改后的依赖安装步骤如下:

    - script: pip install ansible
      displayName: 'Install Ansible'
    
    - script: ansible-galaxy collection install azure.azcollection
      displayName: 'Install Ansible Azure Collection' 
    
    - script: pip install -r https://raw.githubusercontent.com/ansible-collections/azure/dev/requirements-azure.txt
      displayName: 'Install Azure modules needed'
    
    - script: pip install azure-storage==0.36.0
      displayName: 'Install legacy Azure Storage SDK'
    
  • 可选验证步骤:
    新增流水线步骤检查已安装的依赖包,确认旧版存储包已成功安装:

    pip list | grep azure
    

内容的提问来源于stack exchange,提问作者Jan van Veldhuizen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 10:20:42