python - Ansible 错误 - 没有名为 package.version 的模块

标签 python azure ansible

我有 Centos 7.3 和 ansible 版本 2.3。

Ansible 2.3.0.0
config file = ../ansible.cfg
configured module search path = Default w/o overrides
python version = 2.7.5 (default, Nov  6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]

我需要在 Azure VM 中运行 ansible playbook。

运行时出现以下错误

fatal: [52.170.201.24]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Shared connection to 52.170.201.24 closed.\r\n", 
"module_stdout": "\r\nTraceback (most recent call last):\r\n  File \"/tmp/ansible_k2CnFR/ansible_module_azure_rm_virtualmachine.py\", line 445, in <module>\r\n    
from ansible.module_utils.azure_rm_common import *\r\n  
File \"/tmp/ansible_k2CnFR/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py\", line 29, in <module>\r\nImportError: No module named packaging.version\r\n", "msg": "MODULE FAILURE", "rc": 0}

尝试安装多个站点中所示的安装工具

sudo pip install setuptools
Requirement already satisfied: setuptools in /root/.local/lib/python2.7/site-packages
Requirement already satisfied: six>=1.6.0 in /root/.local/lib/python2.7/site-packages (from setuptools)
Requirement already satisfied: appdirs>=1.4.0 in /root/.local/lib/python2.7/site-packages (from setuptools)
Requirement already satisfied: packaging>=16.8 in /root/.local/lib/python2.7/site-packages (from setuptools)
Requirement already satisfied: pyparsing in /root/.local/lib/python2.7/site-packages (from packaging>=16.8->setuptools

尝试按照多个站点中提到的方式升级 pip 并将其升级到最新版本

pip -V
pip 9.0.1 from /usr/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg (python 2.7)

which pip
/usr/bin/pip
$ which pip3
/usr/local/bin/pip3
$ which python
/usr/bin/python

更新:

52.170.201.24 是作为 list 主机一部分的 Azure 虚拟机的 IP 地址。

我实际上正在尝试使用我的 ansible 控制机中的此 ansible 代码来启动 Azure 虚拟机

- name: Power On Docker repo if Azure
  azure_rm_virtualmachine:
    resource_group: HpsaPoc
    name: DockerRepo
    started: yes
  when:  "{{cloud_provider}}" == 'azure'

我无法理解这个 python/pip 配置,我尝试安装 python 3.5 和 pip3 但没有帮助,所以删除了它,因为我不知道如何卸载它。请帮忙。

最佳答案

似乎您尝试从远程主机而不是 Ansible 控制主机执行 azure_rm_virtualmachine

尝试:

- name: Power On Docker repo if Azure
  azure_rm_virtualmachine:
    resource_group: HpsaPoc
    name: DockerRepo
    started: yes
  when: cloud_provider == 'azure'
  delegate_to: localhost

关于python - Ansible 错误 - 没有名为 package.version 的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44272205/

相关文章:

Ansible 取消归档 : "Failed to find handler"

ansible - 如何在Ansible角色测试中禁用分子幂等性检查?

python - 如何计算选定范围的平均值?(pandas)

python - Python 中带有变量指数的科学记数法文字

azure - Kubernetes 中的 Flink 作业部署

linux - kubernetes pods 显示与主机不同的 ulimit 打开文件

python - 无法将 ansible yml 文件中的 dict 键值获取到我的 after.yml 文件中

python - 从 pandas df 中的列创建二元组

python - 提交 django 表单集时出现 MultiValueDictKeyError

azure - 多域 SSL 证书和 Windows Azure