ansible playbook 错误是:ModuleNotFoundError:尽管已安装模块,但没有名为“azure.mgmt.monitor.version”的模块

问题描述 投票:0回答:4

将ansible升级到版本2.10.5和python3.8.10后,我的playbook.yml失败并出现此错误。

ModuleNotFoundError: No module named 'azure.mgmt.monitor.version'
fatal: [localhost]: FAILED! => {"attempts": 1, "changed": false, "msg": "Failed to import the required Python library (ansible[azure] (azure >= 2.0.0)) on certrenewplay's Python /usr/bin/python3`

如果我运行

python3 -c  "import azure.mgmt.monitor"
,该模块就在那里,如果我运行
pip3 list
,我会看到它安装为
azure-mgmt-monitor==2.0.0

剧本代码中出错的确切部分是这样的:

 - name: Create _acme-challenge record for zone "{{ env_name_dot }}"
   azure_rm_dnsrecordset:
    subscription_id: "{{ mgmt_subscription }}"
    client_id: "{{ mgmt_vault_azure_client_id }}"
    tenant: "{{ mgmt_vault_azure_tenant_id }}"
    secret: "{{ mgmt_vault_azure_client_secret }}"
    resource_group: "{{ mgmt_rg }}"
    relative_name: "_acme-challenge.{{ env_name }}"
    zone_name: "{{ dns_zone_name }}.{{ dns_zone_domain }}"
    record_type: TXT
    state: present
    records:
      - entry: "{{ cn_challenge_data }}"
    time_to_live: 60
  when: dns_zone_name != 'activedrop'
  register: add_record
  retries: 1
  delay: 10

  until: add_record is succeeded

我不确定我做错了什么 - 有人可以建议或帮助我吗? 谢谢

python-3.x azure ansible ansible-2.x
4个回答
4
投票

同样的问题也发生在我身上,因为 Ansible 现在附带了自己的 Azure 集合版本,并且它与我使用“ansible-galaxy collection”命令在自己的 playbook 中手动安装的版本冲突。

我建议您只使用 Ansible 附带的版本,然后安装其要求,如下所示:

pip install -r /usr/lib/python3/dist-packages/ansible_collections/azure/azcollection/requirements-azure.txt

在新安装的系统(例如在 Docker 中)上正确设置比修复损坏的系统更容易。


0
投票

我认为您没有遵循https://github.com/ansible-collections/azure

有关安装azure集合的说明

安装集合本身不会安装 python 依赖项,这些依赖项是使用 python pip 安装的,您需要确保将它们安装在安装 ansible 的同一个 python (v)env 中,否则 ansible 会给您在以下情况下看到的错误正在尝试加载模块。


0
投票

不幸的是,azure-mgmt-monitor 包存在 bug,即使在 3.0.0 上也无法正确创建版本子模块。无法准确追踪代码中的错误位置,但确实如此,并且 Ansible Galaxy 模块中直接导入了该子模块,导致其失败。不幸的是,您此时应该使用 Azure CLI,而忘记使用

azure_rm


0
投票

对我来说,解决方案是添加

delegate_to 127.0.0.1
。该软件包安装在我的本地计算机上,但没有安装在远程服务器上,但默认情况下 Ansible 希望
from azure.mgmt.core.tools
安装在未安装 azure 要求的远程服务器上。

© www.soinside.com 2019 - 2024. All rights reserved.