Ensure `~/.ssh` exists before SSH keyscanning.
@@ -10,6 +10,8 @@ Eg: ``pyinfra -> inventory-host.net <-> another-host.net``
from pyinfra.api import operation, OperationError
+from . import files
+
@operation
def keyscan(state, host, hostname, force=False):
@@ -20,6 +22,12 @@ def keyscan(state, host, hostname, force=False):
+ force: if the key already exists, remove and rescan
'''
+ yield files.directory(
+ state, host,
+ '~/.ssh',
+ mode=700,
+ )
+
hostname_present = host.fact.find_in_file(
'~/.ssh/known_hosts',
hostname,
