2017-07-25 108 views
0

使用testinfra(Pytest插件)进行测试。我想用私钥来测试Jenkins的远程主机。用私钥testinfra ssh执行

[[email protected] tests]# testinfra --ssh-config=/path/to/private/key --sudo [email protected] test.py

其中

cat /path/to/private/key 
-----BEGIN RSA PRIVATE KEY----- 
(...) 
-----END RSA PRIVATE KEY----- 

cat test.py 
def test_redis_is_installed(host): 
    redis = host.package("redis") 
    assert redis.is_installed 

我得到的是

E    Exception: Unparsable line -----BEGIN RSA PRIVATE KEY----- 

/usr/lib/python2.7/site-packages/paramiko/config.py:68: Exception 
================================================================================= warnings summary ================================================================================== 
None 
    Module already imported so can not be re-written: testinfra 

-- Docs: http://doc.pytest.org/en/latest/warnings.html 
======================================================================= 1 failed, 1 warnings in 0.23 seconds ======================================================================== 

好像的paramiko不喜欢这种格式,但试了其它b- ackends,它不工作。我怎样才能通过私钥?

回答

0

--ssh-config必须是ssh的路径config。您在该配置中为主机配置密钥对。

喜欢的东西在〜/ .ssh /配置:

Host remotehost 
    User user 
    IdentityFile remotehost-key