【问题标题】:ansible - python lxml issue with maven_artifact moduleansible - maven_artifact 模块的 python lxml 问题
【发布时间】:2016-02-05 12:43:12
【问题描述】:

我有 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 主页上的路径

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

【问题讨论】:

    标签: python-2.7 lxml ansible ansible-playbook


    【解决方案1】:

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

    就我而言,我只想在本地“ansible_host”上运行命令,所以我只是添加了“local_action”前缀,然后命令运行。

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

    【讨论】:

      【解决方案2】:

      我通常做的是打电话:

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

      【讨论】:

        【解决方案3】:

        做事

        sudo apt-get install python-lxml

        【讨论】:

          【解决方案4】:

          你需要在[test01vm1]中安装lxml。

          pip install lxml
          

          【讨论】:

            【解决方案5】:

            验证目标机器有python lxml模块,ansible选择你安装lxml模块的python解释器。

            [ec2-user@i-05f345345aas6b bin]$ pip list | grep xml
            lxml            3.2.1
            

            然后通过添加来仔细检查 ansible 是否选择了该 python 版本:

            ansible_python_interpreter=/usr/bin/python2
            

            https://docs.ansible.com/ansible/latest/reference_appendices/interpreter_discovery.html

            我观察到 ansible 2.12 默认选择 python3 解释器,如果目标机器中没有定义 python 解释器。所以仔细检查

            pip3 list | grep lxml
            

            该 lxml 模块也可用于 python3

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2017-11-30
              • 1970-01-01
              • 1970-01-01
              • 2017-07-28
              • 2021-04-23
              • 2011-07-17
              • 1970-01-01
              相关资源
              最近更新 更多