code: def keyscan(state, host, hostname, force=False):
      '''
      Check/add hosts to the ``~/.ssh/known_hosts`` file.
  
      + hostname: hostname that should have a key in ``known_hosts``
      + 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,
      )
  
      keyscan_command = 'ssh-keyscan {0} >> ~/.ssh/known_hosts'.format(hostname)
  
      if not hostname_present:
          yield keyscan_command
  
      elif force:
          yield 'ssh-keygen -R {0}'.format(hostname)
          yield keyscan_commanf keyscan(state, host, hostname, force=False):
      '''
      Check/add hosts to the ``~/.ssh/known_hosts`` file.
  
      + hostname: hostname that should have a key in ``known_hosts``
      + 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,
      )
  
      keyscan_command = 'ssh-keyscan {0} >> ~/.ssh/known_hosts'.format(hostname)
  
      if not hostname_present:
          yield keyscan_command
  
      elif force:
          yield 'ssh-keygen -R {0}'.format(hostname)
          yield keyscan_command
docs: Check/add hosts to the ``~/.ssh/known_hosts`` file.
  
      + hostname: hostname that should have a key in ``known_hosts``
      + force: if the key already exists, remove and rescan