Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in cups_lpadmin.py while running role #2

Closed
JonTheNiceGuy opened this issue May 6, 2017 · 3 comments
Closed

Error in cups_lpadmin.py while running role #2

JonTheNiceGuy opened this issue May 6, 2017 · 3 comments

Comments

@JonTheNiceGuy
Copy link
Contributor

With Ubuntu 16.04 using

ansible 2.3.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]

Here's the play item which has errored, when I run ansible-playbook with -vvv

TASK [HP41.cups : Install printers using cups_lpadmin] ******************************************************************************************
task path: /etc/ansible/roles/HP41.cups/tasks/printer_and_class_install.yml:14
Using module file /etc/ansible/roles/HP41.cups/library/cups_lpadmin.py
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: root
<localhost> EXEC /bin/sh -c 'echo ~ && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1494079292.48-254030271278802 `" && echo ansible-tmp-1494079292.48-254030271278802="` echo /root/.ansible/tmp/ansible-tmp-14940
79292.48-254030271278802 `" ) && sleep 0'
<localhost> PUT /tmp/tmpJwH5cU TO /root/.ansible/tmp/ansible-tmp-1494079292.48-254030271278802/cups_lpadmin.py
<localhost> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1494079292.48-254030271278802/ /root/.ansible/tmp/ansible-tmp-1494079292.48-254030271278802/cups_lpadmin.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1494079292.48-254030271278802/cups_lpadmin.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1494079292.48-254030271278802/" > /dev/null 2>&1 && slee
p 0'
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_ji0fa4/ansible_module_cups_lpadmin.py", line 1187, in <module>
    main()
  File "/tmp/ansible_ji0fa4/ansible_module_cups_lpadmin.py", line 1180, in main
    result_info = cups_command.start_process()
  File "/tmp/ansible_ji0fa4/ansible_module_cups_lpadmin.py", line 1104, in start_process
    self.printer_install()
  File "/tmp/ansible_ji0fa4/ansible_module_cups_lpadmin.py", line 1040, in printer_install
    if self.exists_self() and not self.printer_check_cups_options():
  File "/tmp/ansible_ji0fa4/ansible_module_cups_lpadmin.py", line 856, in printer_check_cups_options
    'printer-make-and-model': self._printer_get_make_and_model(),
  File "/tmp/ansible_ji0fa4/ansible_module_cups_lpadmin.py", line 593, in _printer_get_make_and_model
    installed_drivers = self._printer_get_installed_drivers()
  File "/tmp/ansible_ji0fa4/ansible_module_cups_lpadmin.py", line 542, in _printer_get_installed_drivers
    curr[kv[0]] = kv[1]
TypeError: 'itertools.imap' object has no attribute '__getitem__'

failed: [localhost] (item={u'info': u'HP Officejet 6500 e709n', u'name': u'HPPrinter', u'driver': u'drv:///hpcups.drv/hp-officejet_6500_e709n.ppd', u'uri': u'hp:/net/Officejet_6500_E709n?ip=192.168.1.55', u'default_pri
nter': True, u'location': u'Playroom', u'shared': True}) => {
    "failed": true, 
    "item": {
        "default_printer": true, 
        "driver": "drv:///hpcups.drv/hp-officejet_6500_e709n.ppd", 
        "info": "HP Officejet 6500 e709n", 
        "location": "Playroom", 
        "name": "HPPrinter", 
        "shared": true, 
        "uri": "hp:/net/Officejet_6500_E709n?ip=192.168.1.55"
    }, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_ji0fa4/ansible_module_cups_lpadmin.py\", line 1187, in <module>\n    main()\n  File \"/tmp/ansible_ji0fa4/ansible_module_cups_lpadmin.py\"
, line 1180, in main\n    result_info = cups_command.start_process()\n  File \"/tmp/ansible_ji0fa4/ansible_module_cups_lpadmin.py\", line 1104, in start_process\n    self.printer_install()\n  File \"/tmp/ansible_ji0fa4
/ansible_module_cups_lpadmin.py\", line 1040, in printer_install\n    if self.exists_self() and not self.printer_check_cups_options():\n  File \"/tmp/ansible_ji0fa4/ansible_module_cups_lpadmin.py\", line 856, in printe
r_check_cups_options\n    'printer-make-and-model': self._printer_get_make_and_model(),\n  File \"/tmp/ansible_ji0fa4/ansible_module_cups_lpadmin.py\", line 593, in _printer_get_make_and_model\n    installed_drivers = 
self._printer_get_installed_drivers()\n  File \"/tmp/ansible_ji0fa4/ansible_module_cups_lpadmin.py\", line 542, in _printer_get_installed_drivers\n    curr[kv[0]] = kv[1]\nTypeError: 'itertools.imap' object has no attr
ibute '__getitem__'\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE", 
    "rc": 0
}

This is the line I get when I run lpinfo -m | grep e709n

drv:///hpcups.drv/hp-officejet_6500_e709n.ppd HP Officejet 6500 e709n, hpcups 3.16.3
@HP41
Copy link
Owner

HP41 commented Jun 20, 2017

Sorry about getting back late, do a lpinfo -l -m instead.

The function dealing with the printer driver enumeration is the following:

library/cups_lpadmin.py#L503-L547

So far I've seen lpinfo -l -m only return the results in the following format (mac, 14.04 and 16.04):

Model:  name = drv:///sample.drv/zebracpl.ppd
             natural_language = en
             make-and-model = Zebra CPCL Label Printer
             device-id =

if in above format, it should be able to parse and create the appropriate driver list

@pghmcfc
Copy link

pghmcfc commented Sep 27, 2017

This looks similar to ansible/ansible-modules-extras/pull/3350; changing

kv = map(str.strip, kv)

at line 540 to

kv = tuple(map(str.strip, kv))

fixes this traceback for me.

HP41 added a commit that referenced this issue Apr 4, 2018
@HP41
Copy link
Owner

HP41 commented Apr 4, 2018

That seems to have fixed it!
Thanks @pghmcfc !
Sorry for the late reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants