ansible - 与maven_artifact模块的python lxml问题

时间:2016-02-05 12:43:12

标签: python-2.7 lxml ansible ansible-playbook

我有ansible(v2.0.0.2)和python(v2.7.6),我正在运行'maven_artifact'模块。

作为一个直接的ansible命令,它工作正常

ansible localhost -m maven_artifact -a "group_id=commons-collections artifact_id=commons-collections dest=/tmp/commons-collections-latest.jar" -vvvv

但是当我通过剧本做同样的事情时

- name: download via maven
maven_artifact: group_id=junit artifact_id=junit dest=/tmp/junit-latest.jar

它因此错误而失败

fatal: [test01vm1]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_name": "maven_artifact"}, 
"module_stderr": "", 
"module_stdout": "\r\nTraceback (most recent call last):\r\n  
File \"/home/admin123/.ansible/tmp/ansible-tmp-1454675562.75-201853614879442/maven_artifact\",
line 25, in <module>\r\n    from lxml import etree\r\nImportError: 
No module named lxml\r\n", "msg": "MODULE FAILURE", "parsed": false}

我相信可能与python lxml模块有关,我找到了这些现有的门票

http://stackoverflow.com/questions/13355984/get-errors-when-import-lxml-etree-to-python
http://stackoverflow.com/questions/4598229/installing-lxml-module-in-python

我想知道有人可能有解决方法吗?

编辑 - 添加python路径详细信息

我运行此命令以查看python home上的路径

14:55:11@pcZBook-15:/usr/local/etc$ python -c 'import sys; print(":".join(sys.path))'

文件夹列表是

:/opt/stack/keystone
:/opt/stack/glance
:/opt/stack/cinder
:/opt/stack/nova
:/opt/stack/horizon
:/usr/lib/python2.7
:/usr/lib/python2.7/plat-x86_64-linux-gnu
:/usr/lib/python2.7/lib-tk
:/usr/lib/python2.7/lib-old
:/usr/lib/python2.7/lib-dynload
:/usr/local/lib/python2.7/dist-packages
:/usr/lib/python2.7/dist-packages
:/usr/lib/python2.7/dist-packages/PILcompat
:/usr/lib/python2.7/dist-packages/gtk-2.0
:/usr/lib/pymodules/python2.7
:/usr/lib/python2.7/dist-packages/ubuntu-sso-client
:/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode

3 个答案:

答案 0 :(得分:3)

似乎ansible试图在远程目标主机上执行'maven_artifact'命令,该主机没有所需的python库。

在我的情况下,我只想在本地'ansible_host'上运行命令,所以我只是添加了'local_action'前缀并且命令运行。

- name: download via maven
  local_action: maven_artifact group_id=junit artifact_id=junit dest=/tmp/junit-latest.jar

答案 1 :(得分:3)

我通常做的是致电:

- name: Install PIP
  apt: name=python-pip state=present

- name: Install lxml
  pip: name=lxml

答案 2 :(得分:1)

只做

  

sudo apt-get install python -lxml