2016-08-29 9 views
0

서버에서 병렬 ssh를 수행하려고합니다. 이 일을하는 동안 나는 "TypeError : 'NoneType'개체가 반복 가능하지 않습니다. '라는 오류가 발생합니다. 친절하게 도와주세요."TypeError : 'NoneType'객체가 병렬 ssh를 수행하는 동안 반복 가능하지 않습니다.

내 스크립트

from pssh import ParallelSSHClient 
from pssh.exceptions import AuthenticationException, UnknownHostException, ConnectionErrorException 

def parallelsshjob(): 
     client = ParallelSSHClient(['10.84.226.72','10.84.226.74'], user = 'root', password = 'XXX') 
     try: 
       output = client.run_command('racadm getsvctag', sudo=True) 
       print output 
     except (AuthenticationException, UnknownHostException, ConnectionErrorException): 
       pass 
     #print output 

if __name__ == '__main__': 
     parallelsshjob() 

이하 그리고 역 추적은

Traceback (most recent call last): 
    File "parallelssh.py", line 17, in <module> 
    parallelsshjob() 
    File "parallelssh.py", line 10, in parallelsshjob 
    output = client.run_command('racadm getsvctag', sudo=True) 
    File "/Library/Python/2.7/site-packages/pssh/pssh_client.py", line 520, in run_command 
    raise ex 
TypeError: 'NoneType' object is not iterable 

이 솔루션을 도와 또한이 같은 스크립트에서 SSH 에이전트를 사용하는 날을 제안 다음과 같습니다. 미리 감사드립니다.

답변

1

내 랩톱에서 코드를 읽고 디버깅하는 것에서부터 나는 ~/.ssh/config이라는 파일이 없다고 생각합니다. parallel-ssh에는 OpenSSH 구성에 대한 종속성이있는 것으로 보이며,이 파일이 누락 된 경우 발생하는 오류입니다.

read_openssh_config 반환 여기 없음 : https://github.com/pkittenis/parallel-ssh/blob/master/pssh/ssh_client.py#L97 : 그것은받을 것으로 기대 값을 압축 할 때 회전에서 https://github.com/pkittenis/parallel-ssh/blob/master/pssh/utils.py#L79

SSHClient.__init__ 불면.

이 수정 프로그램은 일종의 OpenSSH 구성 파일을 얻는 것으로 추정되지만 아마도 그 사실에 대해 아무것도 모른다고해서 유감스럽게 생각합니다.

편집

parallel-ssh의 예외 처리의 일부를 정리 한 후, 여기에 오류에 대한 더 나은 스택 추적입니다 :

Traceback (most recent call last): 
    File "test.py", line 11, in <module> 
    parallelsshjob() 
    File "test.py", line 7, in parallelsshjob 
    output = client.run_command('racadm getsvctag', sudo=True) 
    File "/Users/smarx/test/pssh/venv/lib/python2.7/site-packages/pssh/pssh_client.py", line 517, in run_command 
    self.get_output(cmd, output) 
    File "/Users/smarx/test/pssh/venv/lib/python2.7/site-packages/pssh/pssh_client.py", line 601, in get_output 
    (channel, host, stdout, stderr, stdin) = cmd.get() 
    File "/Users/smarx/test/pssh/venv/lib/python2.7/site-packages/gevent/greenlet.py", line 480, in get 
    self._raise_exception() 
    File "/Users/smarx/test/pssh/venv/lib/python2.7/site-packages/gevent/greenlet.py", line 171, in _raise_exception 
    reraise(*self.exc_info) 
    File "/Users/smarx/test/pssh/venv/lib/python2.7/site-packages/gevent/greenlet.py", line 534, in run 
    result = self._run(*self.args, **self.kwargs) 
    File "/Users/smarx/test/pssh/venv/lib/python2.7/site-packages/pssh/pssh_client.py", line 559, in _exec_command 
    channel_timeout=self.channel_timeout) 
    File "/Users/smarx/test/pssh/venv/lib/python2.7/site-packages/pssh/ssh_client.py", line 98, in __init__ 
    host, config_file=_openssh_config_file) 
TypeError: 'NoneType' object is not iterable 
0

지금 0.92.1에서 해결이 was seemingly a regression in the 0.92.0 version of the library. 이전 버전도 작동합니다. OpenSSH 설정 이 아니어야합니다.

SSH 에이전트 질문에 대답하려면 사용자 세션에서 실행되고 활성화되어 있으면 자동으로 사용됩니다. 당신이 개인 키를 제공하기 위해 원하는 경우 프로그래밍 다음

from pssh import ParallelSSHClient 
from pssh.utils import load_private_key 
pkey = load_private_key('my_private_key') 
client = ParallelSSHClient(hosts, pkey=pkey) 

도 추가 예제

아래
from pssh import ParallelSSHClient 
from pssh.utils import load_private_key 
from pssh.agent import SSHAgent 
pkey = load_private_key('my_private_key') 
agent = SSHAgent() 
agent.add_key(pkey) 
client = ParallelSSHClient(hosts, agent=agent) 

See documentation 당, 프로그래밍 여러 개의 키와 에이전트를 제공 할 수 할 수 있습니다.