old_contents: #!/usr/bin/env python
  
  import time
  
  import paramiko
  
  from st2actions.runners.pythonrunner import Action
  
  
  class BaseAction(Action):
      def run(self, keyfile, username, hostname, ssh_timeout, retries):
          key = paramiko.RSAKey.from_private_key_file(keyfile)
          client = paramiko.SSHClient()
          client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  
          for x in range(retries):
              try:
                  client.connect(hostname=hostname, username=username, pkey=key)
                  return True
              except Exception, e:
                  self.logger.info(e)
                  time.sleep(ssh_timeout)
              time.sleep(20)
  
          raise Exception("Exceeded max retries")
  
new_contents: #!/usr/bin/env python
  
  import time
  
  import paramiko
  
  from st2actions.runners.pythonrunner import Action
  
  
  class BaseAction(Action):
      def run(self, keyfile, username, hostname, ssh_timeout, retries):
          key = paramiko.RSAKey.from_private_key_file(keyfile)
          client = paramiko.SSHClient()
          client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  
          for index in range(retries):
              attempt = index + 1
  
              try:
                  self.logger.debug('SSH connection attempt: %s' % (attempt))
                  client.connect(hostname=hostname, username=username, pkey=key)
                  return True
              except Exception as e:
                  self.logger.info('Attempt %s failed (%s), sleeping...' % (attempt, str(e)))
                  time.sleep(ssh_timeout)
  
          raise Exception('Exceeded max retries (%s)' % (retries))
  
subject: Improve logging in wait_for_ssh action, remove unecessary second sleep.