Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. import subprocess
  2.  
  3. from ansible.plugins.connection.ssh import Connection as ConnectionSSH
  4. from ansible.errors import AnsibleError
  5. from socket import create_connection
  6. from time import sleep
  7.  
  8. try:
  9. from __main__ import display
  10. except ImportError:
  11. from ansible.utils.display import Display
  12. display = Display()
  13.  
  14. class Connection(ConnectionSSH):
  15.  
  16. def __init__(self, *args, **kwargs):
  17.  
  18. super(Connection, self).__init__(*args, **kwargs)
  19. display.vvv("ssh_fwknop connection plugin is used for this host", host=self.host)
  20.  
  21. def set_host_overrides(self, host, hostvars=None):
  22.  
  23. p = subprocess.Popen(['/usr/bin/fwknop', '-n', '%s' % (host)], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  24. stdout, stderr = p.communicate()
  25. status_code = p.wait()
  26. if status_code != 0:
  27. raise AnsibleError("fwknop error:\n%s" % stderr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement