andreasscherbaum / ansible-lxc-ssh

Ansible connection plugin using ssh + lxc-attach
45 stars 22 forks source link

AttributeError: 'Connection' object has no attribute 'sshpass_pipe' #20

Closed tlc closed 5 years ago

tlc commented 5 years ago

Having this issue using

$ ansible-playbook --version ansible-playbook 2.7.8

I am using -k and a password.

TASK [robertdebock.bootstrap : register apk] ***********************************
task path: /home/tlc/playbooks/roles/robertdebock.bootstrap/tasks/main.yml:27
XXX connect
<reducto.home> ESTABLISH SSH CONNECTION FOR USER: root
<reducto.home> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/home/tlc/.ansible/cp/00f460a8d5 -tt reducto.home 'which lxc'
The full traceback is:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/ansible/executor/task_executor.py", line 140, in run
    res = self._execute()
  File "/usr/lib/python2.7/dist-packages/ansible/executor/task_executor.py", line 553, in _execute
    self._connection = self._get_connection(variables=variables, templar=templar)
  File "/usr/lib/python2.7/dist-packages/ansible/executor/task_executor.py", line 846, in _get_connection
    ansible_playbook_pid=to_text(os.getppid())
  File "/usr/lib/python2.7/dist-packages/ansible/plugins/loader.py", line 397, in get
    obj = obj(*args, **kwargs)
  File "/home/tlc/playbooks/plugins/lxc_ssh.py", line 155, in __init__
    (returncode2, stdout2, stderr2) = self._exec_command("which lxc", None, False)
  File "/home/tlc/playbooks/plugins/lxc_ssh.py", line 1094, in _exec_command
    (returncode, stdout, stderr) = self._run(cmd, in_data, sudoable=sudoable)
  File "/home/tlc/playbooks/plugins/lxc_ssh.py", line 101, in wrapped
    return_tuple = func(self, *args, **kwargs)
  File "/home/tlc/playbooks/plugins/lxc_ssh.py", line 822, in _run
    return self._bare_run(cmd, in_data, sudoable, checkrc)
  File "/home/tlc/playbooks/plugins/lxc_ssh.py", line 585, in _bare_run
    os.close(self.sshpass_pipe[0])
AttributeError: 'Connection' object has no attribute 'sshpass_pipe'

fatal: [play1.home]: FAILED! => {}

MSG:

Unexpected failure during module execution.
andreasscherbaum commented 5 years ago

Is this error reproducible?

tlc commented 5 years ago

Yep.

tlc commented 5 years ago

A comment says

    # If we are using SSH password authentication, write the password into
    # the pipe we opened in _build_command.

But I don't see a pipe opened in _build_command. Also, I only see sshpass_pipe used in the PY3 case.

andreasscherbaum commented 5 years ago

Looks like no one used that code path before (and I just basically took that over from othe previous author).

_build_command() is never opening a pipe using sshpass_pipe, but I don't know why the code is even trying to recreate them in line 585.

@tlc Can you write a patch which will fix this problem?

tlc commented 5 years ago

@andreasscherbaum Are you saying that use of passwords (-k) have never been tested? But ssh keys work?

andreasscherbaum commented 5 years ago

@tlc At least not by me. If you look at the fork history, this repo was forked from "chifflier" who wrote the initial version. I only made additional changes and updates, with help from others.

andreasscherbaum commented 5 years ago

@tlc Do you plan to look into this issue, otherwise I plan to close it.

tlc commented 5 years ago

You're going to close an issue because the reporter won't fix it?

andreasscherbaum commented 5 years ago

I briefly looked into the code, but could not identify the problem. Also I don't find the use case "enter a password every time" compelling enough for a system which relies on automation all the way.

I can keep the issue open if you like, but I don't plan to spend more time on it. That's why I asked if you plan to dig deeper. If you can provide a PR which will fix the problem, I'm happy to merge it.

azlux commented 4 years ago

I've hit the same today. But I'm python3.

The full traceback is:
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/ansible/executor/task_executor.py", line 146, in run
    res = self._execute()
  File "/usr/local/lib/python3.7/dist-packages/ansible/executor/task_executor.py", line 601, in _execute
    self._connection = self._get_connection(variables=variables, templar=templar)
  File "/usr/local/lib/python3.7/dist-packages/ansible/executor/task_executor.py", line 892, in _get_connection
    ansible_playbook_pid=to_text(os.getppid())
  File "/usr/local/lib/python3.7/dist-packages/ansible/plugins/loader.py", line 573, in get
    obj = obj(*args, **kwargs)
  File "/root/ansible/connection_plugins/lxc_ssh.py", line 137, in __init__
    (returncode2, stdout2, stderr2) = self._exec_command("which lxc", None, False)
  File "/root/ansible/connection_plugins/lxc_ssh.py", line 685, in _exec_command
    (returncode, stdout, stderr) = self._run(cmd, in_data, sudoable=sudoable)
  File "/root/ansible/connection_plugins/lxc_ssh.py", line 84, in wrapped
    return_tuple = func(self, *args, **kwargs)
  File "/root/ansible/connection_plugins/lxc_ssh.py", line 664, in _run
    return self._bare_run(cmd, in_data, sudoable, checkrc)
  File "/root/ansible/connection_plugins/lxc_ssh.py", line 409, in _bare_run
    p = subprocess.Popen(cmd, stdin=slave, stdout=subprocess.PIPE, stderr=subprocess.PIPE, pass_fds=self.sshpass_pipe)
AttributeError: 'Connection' object has no attribute 'sshpass_pipe'

101 | FAILED! => {
    "msg": "Unexpected failure during module execution.",
    "stdout": ""
}
andreasscherbaum commented 4 years ago

Again, if someone can provide a working PR for the issue where you enter a password all the time, I'm happy to merge it.