kewlfft / ansible-aur

Ansible module to manage packages from the AUR
GNU General Public License v3.0
294 stars 46 forks source link

Support Python 2 - 'module' object has no attribute 'TemporaryDirectory #18

Closed dmp1ce closed 6 years ago

dmp1ce commented 6 years ago

I am using the install trizen example in a role called aur_builder here:

# AUR builder related tasks
- name: Create aur_builder user
  user:
    name: aur_builder
    group: wheel
- name: Allow aur_builder to run pacman as root
  lineinfile:
    path: /etc/sudoers.d/11-install-aur_builder
    line: 'aur_builder ALL=(ALL) NOPASSWD: /usr/bin/pacman'
    create: yes
    validate: 'visudo -cf %s'

# Install trizen using makepkg, skip if trizen is already installed
- name: Install trizen
  aur: name=trizen use=makepkg skip_installed=true
  become: yes
  become_user: aur_builder

and I'm getting the following error.

TASK [aur_builder : Install trizen] ********************************************
fatal: [default]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 127.0.0.1 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible_UQa5Xn/ansible_module_aur.py\", line 255, in <module>\r\n    main()\r\n  File \"/tmp/ansible_UQa5Xn/ansible_module_aur.py\", line 251, in main\r\n    install_packages(module, params['name'], use, params['skip_installed'], params['aur_only'])\r\n  File \"/tmp/ansible_UQa5Xn/ansible_module_aur.py\", line 180, in install_packages\r\n    rc, out, err = install_with_makepkg(module, package)\r\n  File \"/tmp/ansible_UQa5Xn/ansible_module_aur.py\", line 135, in install_with_makepkg\r\n    with tempfile.TemporaryDirectory() as tmpdir:\r\nAttributeError: 'module' object has no attribute 'TemporaryDirectory'\r\n", "msg": "MODULE FAILURE", "rc": 1}

Am I missing something or is this a new bug?

My version of ansible is:

ansible --version
ansible 2.6.1
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/david/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.6 (default, Jun 27 2018, 13:11:40) [GCC 8.1.1 20180531]
kewlfft commented 6 years ago

I can't reproduce it, were you able to identify the cause of it?

dmp1ce commented 6 years ago

I'm getting the error from a Vagrant configuration. I'm working a a simple example to show you. The Vagrant box I am using is archlinux/archlinux.

I was able to get this message after running on a Vagrant machine which already had Trizen installed.

TASK [Install trizen] **********************************************************
 [WARNING]: Module remote_tmp /home/aur_builder/.ansible/tmp did not exist and
was created with a mode of 0700, this may cause issues when running as another
user. To avoid this, create the remote_tmp dir with the correct permissions
manually

ok: [default] => {"changed": false, "helper": "makepkg", "msg": "package(s) already installed", "rc": 0}
dmp1ce commented 6 years ago

I was using the python2 interpreter. I think that was causing the issue for me. Try setting python interpreter with ansible_python_interpreter: /usr/bin/python2 and see if you can reproduce.

Which version of Python should be used with Ansible? 2 or 3?

kewlfft commented 6 years ago

Since Arch switched a few months ago Ansible to Python 3, this is what I use and recommend. You may want to use this module with version 2 and submit some PR to improve compatibility with Python 2, I will accept them.

dmp1ce commented 6 years ago

I think it will be easier for me to switch to using Python 3. If I cannot do that then I will work on Python 2 support.

kewlfft commented 6 years ago

Not able to reproduce it and no intention to maintain compatibility with Python 2

dmp1ce commented 6 years ago

No problem. I was overriding some python paths so it was probably an issue I created.