Skip to content

Commit f573fb5

Browse files
committed
Use home fact rather than tilde in ssh.keyscan operation.
1 parent 03c76fa commit f573fb5

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

pyinfra/operations/ssh.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pyinfra import logger
1010
from pyinfra.api import operation, OperationError
1111
from pyinfra.facts.files import File, FindInFile
12+
from pyinfra.facts.server import Home
1213

1314
from . import files
1415

@@ -31,21 +32,23 @@ def keyscan(hostname, force=False, port=22, state=None, host=None):
3132
)
3233
'''
3334

35+
homedir = host.get_fact(Home)
36+
3437
yield files.directory(
35-
'~/.ssh',
38+
'{0}/.ssh'.format(homedir),
3639
mode=700,
3740
state=state,
3841
host=host,
3942
)
4043

4144
hostname_present = host.get_fact(
4245
FindInFile,
43-
path='~/.ssh/known_hosts',
46+
path='{0}/.ssh/known_hosts'.format(homedir),
4447
pattern=hostname,
4548
)
4649

47-
keyscan_command = 'ssh-keyscan -p {0} {1} >> ~/.ssh/known_hosts'.format(
48-
port, hostname,
50+
keyscan_command = 'ssh-keyscan -p {0} {1} >> {2}/.ssh/known_hosts'.format(
51+
port, hostname, homedir,
4952
)
5053

5154
if not hostname_present:

0 commit comments

Comments
 (0)