据我所知,我安装了所有依赖项来使用我的Ansible剧本中的azure模块,但是我仍然会收到这个错误。
The full traceback is:
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)我的剧本:
---
- name: config azure environment
hosts: localhost
connection: local
gather_facts: true
collections:
- azure.azcollection
vars_files:
- group_vars/common.yml
roles:
- roles/resourcegroup以及作用:
---
- name: create a resource group
azure_rm_resourcegroup:
name: "{{ app.name }}-{{ dict.resource_group }}"
location: "{{ azure.location }}"
state: present根据文档(https://docs.ansible.com/ansible/latest/collections/azure/azcollection/azure_rm_resourcegroup_module.html),一切都应该是好的。所以,我错过了什么?我已经搜索了几个小时了,但我还没有找到一个有效的解决方案:
发布于 2022-11-10 18:49:14
在此期间。我有个可行的解决方案。我从头开始,创建了一个Azure管道模板,没有角色。
例如,我使用我的管道来创建一个码头容器注册中心,但是它适用于您想在Azure中使用管道中的播放本所做的任何事情。就用这个例子来学习我是如何让它工作的。希望它能帮助那些在同样的问题上挣扎的人。
- task: Bash@3
displayName: 'create vars file for docker registry playbook'
inputs:
targetType: 'inline'
workingDirectory: './playbooks'
script: |
touch vars.yml
echo 'azure:' > vars.yml
echo ' location: "${{ parameters.azure_location }}"' >> vars.yml
echo ' resourcegroup: "${{ parameters.resourcegroup_name }}"' >> vars.yml
echo ' containerregistry: "${{ parameters.containerregistry_name }}"' >> vars.yml
cat vars.yml
- template: steps/run_ansible.yml
parameters:
playbook: playbooks/setup_dockerhub.yml
varsfile: playbooks/vars.ymlrun_ansible步骤文件:
parameters:
- name: playbook
type: string
- name: varsfile
type: string
steps:
- task: AzureCLI@2
displayName: 'install Azure CLI'
inputs:
#azureSubscription: '$(AZURE_SUBSCRIPTION_NAME)'
connectedServiceNameARM: 'ARM Outstanding24'
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: sudo apt install -y python3-pip
displayName: 'install pip'
- script: sudo pip3 install --upgrade pip
displayName: 'ensure we have the latest version of pip3'
- script: pip3 install "ansible==2.9.17"
displayName: 'install ansible 2.9'
- script: pip3 install ansible[azure]
displayName: 'install ansible "azure modules"'
- script: 'ansible-playbook -v ${{ parameters.playbook }} --extra-vars @${{ parameters.varsfile }}'
displayName: 'run azure playbook'
env:
AZURE_CLIENT_ID: $(ARM_CLIENT_ID)
AZURE_SECRET: $(ARM_CLIENT_SECRET)
AZURE_TENANT: $(ARM_TENANT_ID)
AZURE_SUBSCRIPTION_ID: $(ARM_SUBSCRIPTION_ID)剧本:
- name: setup docker registry in Azure
hosts: localhost
connection: local
gather_facts: false
collections:
- azure.azcollection
vars_files:
- vars.yml
tasks:
- name: ensure the resourcegroup exists
azure_rm_resourcegroup:
name: "{{ azure.resourcegroup }}"
location: "{{ azure.location }}"
state: present
- name: ensure docker registry exists
azure_rm_containerregistry:
name: "{{ azure.containerregistry }}"
location: "{{ azure.location }}"
resource_group: "{{ azure.resourcegroup }}"
sku: Basic
state: presenthttps://stackoverflow.com/questions/74196208
复制相似问题