StackStorm / st2

StackStorm (aka "IFTTT for Ops") is event-driven automation for auto-remediation, incident responses, troubleshooting, deployments, and more for DevOps and SREs. Includes rules engine, workflow, 160 integration packs with 6000+ actions (see https://exchange.stackstorm.org) and ChatOps. Installer at https://docs.stackstorm.com/install/index.html
https://stackstorm.com/
Apache License 2.0
5.96k stars 744 forks source link

No such file or directory: '/home/stanley/.ssh/stanley_rsa #6116

Open doing-cr7 opened 5 months ago

doing-cr7 commented 5 months ago

i got a error when i run core.remote

st2 run core.remote hosts='10.69.10.1:5000' cmd='echo123'
.
id: 65ae14e509204db1549f4a31
action.ref: core.remote
context.user: st2admin
parameters:
  cmd: echo123
  hosts: 10.69.10.1:5000
status: failed
start_timestamp: Mon, 22 Jan 2024 07:10:29 UTC
end_timestamp: Mon, 22 Jan 2024 07:10:29 UTC
result:
  error: "Unable to connect to any one of the hosts: ['10.69.10.1:5000'].

 connect_errors={
  "10.69.10.1": {
    "failed": true,
    "succeeded": false,
    "timeout": false,
    "return_code": 255,
    "stdout": "",
    "stderr": "",
    "error": "Failed connecting to host 10.69.10.1. [Errno 2] No such file or directory: '/home/stanley/.ssh/stanley_rsa'",
    "traceback": "Traceback (most recent call last):\
  File \\"/opt/stackstorm/st2/lib/python3.8/site-packages/st2common/runners/parallel_ssh.py\\", line 278, in _connect\
    client.connect()\
  File \\"/opt/stackstorm/st2/lib/python3.8/site-packages/st2common/runners/paramiko_ssh.py\\", line 171, in connect\
    self.client = self._connect(host=self.hostname, socket=self.bastion_socket)\
  File \\"/opt/stackstorm/st2/lib/python3.8/site-packages/st2common/runners/paramiko_ssh.py\\", line 747, in _connect\
    passphrase_reqd = self._is_key_file_needs_passphrase(self.key_files)\
  File \\"/opt/stackstorm/st2/lib/python3.8/site-packages/st2common/runners/paramiko_ssh.py\\", line 841, in _is_key_file_needs_passphrase\
    cls.from_private_key_file(file, password=None)\
  File \\"/opt/stackstorm/st2/lib/python3.8/site-packages/paramiko/pkey.py\\", line 249, in from_private_key_file\
    key = cls(filename=filename, password=password)\
  File \\"/opt/stackstorm/st2/lib/python3.8/site-packages/paramiko/rsakey.py\\", line 64, in __init__\
    self._from_private_key_file(filename, password)\
  File \\"/opt/stackstorm/st2/lib/python3.8/site-packages/paramiko/rsakey.py\\", line 190, in _from_private_key_file\
    data = self._read_private_key_file(\\"RSA\\", filename, password)\
  File \\"/opt/stackstorm/st2/lib/python3.8/site-packages/paramiko/pkey.py\\", line 321, in _read_private_key_file\
    with open(filename, \\"r\\") as f:\
FileNotFoundError: [Errno 2] No such file or directory: '/home/stanley/.ssh/stanley_rsa'\
"
  }
}"
  traceback: "  File "/opt/stackstorm/st2/lib/python3.8/site-packages/st2actions/container/base.py", line 117, in _do_run
    runner.pre_run()
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/st2common/runners/paramiko_ssh_runner.py", line 206, in pre_run
    self._parallel_ssh_client = ParallelSSHClient(**client_kwargs)
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/st2common/runners/parallel_ssh.py", line 90, in __init__
    connect_results = self.connect(raise_on_any_error=raise_on_any_error)
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/st2common/runners/parallel_ssh.py", line 131, in connect
    raise NoHostsConnectedToException(msg)

but i only exec ssh command is ok

ssh 10.69.10.1 -p 5000

i try

cp ~/.ssh/id_rsa  /home/stanley/.ssh/stanley_rsa

again run

st2 run core.remote hosts='10.69.10.1:5000' cmd='echo123'

error don't resolved

mamercad commented 5 months ago

Does the user account that is running the StackStorm processes have right to read the key?

garadar commented 2 months ago

I have the same error, if you are using a different home than /home/stanley:

getent passwd stanley
stanley:x:900:900::/opt/xxxx/xxx/home/stanley:/bin/bash

but core.remote using remote-shell-cmdby default take a bad value. You can overwritte it using private_key= option or setting a symlink in /home to the home.

garadar commented 2 months ago

OMHO, stackstorm should read the $HOME of stanley instead /home/stanley by default

mamercad commented 2 months ago

OMHO, stackstorm should read the $HOME of stanley instead /home/stanley by default

I wonder if this would help.

garadar commented 2 months ago

indeed it could; I will try Thx

garadar commented 1 month ago

It's 'working' However, the one line command does not work if you create the stanley user with a custom home before the install.