emeraldjava
emeraldjava

Reputation: 11212

ansible - python lxml issue with maven_artifact module

I have ansible (v2.0.0.2) and python (v2.7.6) and i'm running the 'maven_artifact' module.

As a direct ansible command, it works fine

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

but when i do the same via a playbook

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

it fails with this error

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}

I believe might be related to the python lxml module, and i found these existing tickets

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

I'm wondering might someone have a workaround for this?


EDIT - Add python path details

I ran this command to see what path's are on the python home

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

The list of folders is

:/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

Upvotes: 3

Views: 11223

Answers (5)

Verify that target machine has python lxml module, and ansible selects the python interpreter where you have installed the lxml module.

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

And then double check that ansible picks that python version by adding:

ansible_python_interpreter=/usr/bin/python2

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

I have observed that ansible 2.12 ansible picks python3 interpreter by default, if no python interpreter is defined in target machine. So double check with

pip3 list | grep lxml

that lxml module is also available for python3

Upvotes: 0

lcompare
lcompare

Reputation: 997

You need to install lxml in [test01vm1].

pip install lxml

Upvotes: 0

Mariusz Lotko
Mariusz Lotko

Reputation: 384

What I usually do is to call:

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

- name: Install lxml
  pip: name=lxml

Upvotes: 6

Djiby Thiaw
Djiby Thiaw

Reputation: 213

Just do

sudo apt-get install python-lxml

Upvotes: 1

emeraldjava
emeraldjava

Reputation: 11212

It seems that ansible was trying to execute the 'maven_artifact' command on the remote target host, which didn't have the required python libraries.

In my case I only wanted to run the command on the local 'ansible_host' so I just added the 'local_action' prefix and the command runs.

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

Upvotes: 5

Related Questions