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

时间:2017-05-30 21:27:44

标签: 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 playbooks。

运行时出现以下错误

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}

尝试安装几个站点中指示的setuptools

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 -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是Azure虚拟机的IP地址,它是清单主机的一部分。

我实际上是在我的安可控制计算机上尝试使用此安全代码启动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但没有帮助,所以删除它,因为我不知道如何卸载它。请帮忙。

2 个答案:

答案 0 :(得分:2)

由于您的环境没有打包模块,导致出现上述错误。

通过安装打包模块来解决此问题。

pip install packaging

以上命令将安装 16.8版

的打包模块

答案 1 :(得分:1)

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

尝试:

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