0

Using testinfra (Pytest plugin) for testing. I want to test remote hosts from Jenkins using a private key.

[root@jenkins tests]# testinfra --ssh-config=/path/to/private/key \
     --sudo --hosts=user@remotehost test.py

where

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

and

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

What I get is

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 ========================================================================

Seems like paramiko doesn't like this format, but tried other backends and it doesn't work as well. How can I pass the private key then?

slm
  • 15,396
  • 12
  • 109
  • 124
FRC
  • 475
  • 1
  • 8
  • 16

1 Answers1

1

--ssh-config must be a path to ssh config. You configure keypair for the host in that config.

Something like in ~/.ssh/config:

Host remotehost
    User user
    IdentityFile remotehost-key
phd
  • 82,685
  • 13
  • 120
  • 165
  • is it possible to make it work with --ssh-identity-file? Can you maybe check this question https://stackoverflow.com/questions/76581673/execute-testinfra-ssh-using-ssh-identity-file-directly – user14073111 Jun 29 '23 at 16:35